我正在尝试使用Linux Mint下的标志--enable-R-shlib从源代码安装R 3.5.0。在没有标志的情况下进行配置和安装可以正常工作,但是RStudio要求设置标志。但是,运行时
./configure --enable-R-shlib
make
Run Code Online (Sandbox Code Playgroud)
我得到错误
/usr/bin/ld: CommandLineArgs.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
CommandLineArgs.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:177: recipe for target 'libR.so' failed
make[3]: *** [libR.so] Error 1
make[3]: Leaving directory '/home/hps/Downloads/R-3.5.0/src/main'
Makefile:135: recipe for target 'R' failed
make[2]: *** [R] Error 2
make[2]: Leaving directory '/home/hps/Downloads/R-3.5.0/src/main'
Makefile:28: recipe for target 'R' failed
make[1]: *** [R] Error 1
make[1]: …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成 10 对图,每页图有几对,并使用循环for来构造这些图对。但是,这些图会作为单独的图而不是页面发送到设备。
下面的 MWE 对于基础图形和ggplot版本具有相同的结构,但基础图形可以工作,也ggplot可以不工作。我需要做什么才能使第二个版本中的分页正确?
library(ggplot2)
attach(mtcars)
# correct configuration
par(mfrow=c(2,2))
for (ii in 1:3){
vars <- c("wt", "disp", "wt")
plot(get(vars[ii]), mpg)
hist(get(vars[ii]))
}
# places each on separate plot
par(mfrow=c(2,2))
for (ii in 1:3){
vars <- c("wt", "disp", "wt")
p <- ggplot(mtcars, aes(get(vars[ii]), mpg)) + geom_point(size=4)
plot(p)
p <- ggplot(mtcars, aes(get(vars[ii]))) + geom_histogram()
plot(p)
}
detach(mtcars)
Run Code Online (Sandbox Code Playgroud) 我在R中有多个级别列表有问题.这是我的数据结构的一个小例子.
library(purrr)
> example
[[1]]
[[1]][[1]]
id.value id.name value
1 2 Tim -1.68956
2 4 Jack 1.23950
3 5 Mary -0.10897
4 3 Joseph -0.11724
5 1 Kermit 0.18308
[[1]][[2]]
id.value id.name value
1 6 Tim 0.50381
2 2 Jack 2.52834
3 1 Mary 0.54910
4 4 Joseph 0.23821
5 5 Kermit -1.04889
6 3 Red 1.29476
[[1]][[3]]
id.value id.name value
1 4 Tim -0.47279
2 1 Jack -1.06782
3 2 Mary -0.21797
4 3 Joseph -1.02600
5 5 Kermit …Run Code Online (Sandbox Code Playgroud) 使用下面的代码,刻面 bB 中的标签未正确定位。问题似乎源于这样一个事实,即没有position_dodge(preserve="single")for geom_text(对吗?)。我知道我可以“手动”添加一个空的虚拟单元格(在 facet bB 中填充 y=0),但我想知道是否有任何方法可以直接在 ggplot 中纠正它?
v1 <- LETTERS[1:2]
v2 <- letters[1:2]
v3 <- c("x","y")
g <- expand.grid(v1,v2,v3)
val=c(sample(10,8))
df<- data.frame(g,val)
df<- df[-8,]
df %>% ggplot() +
geom_bar(aes(x=Var2, y=val, fill=Var3, group=Var3),
stat="identity",
position=position_dodge(preserve="single"))+
geom_text(aes(x=Var2, y=val+1, label=val, group=Var3),
position=position_dodge(width=1))+
facet_grid(Var1~Var2, scale="free_x")
Run Code Online (Sandbox Code Playgroud)
更新/答案:使用 position_dodge2 将条形与标签对齐(但是,条形居中且未与其他方面中的条形对齐)。
df %>% ggplot() +
geom_bar(aes(x=Var2, y=val, fill=Var3, group=Var3), stat="identity",
position=position_dodge2(preserve="single"))+
geom_text(aes(x=Var2, y=val+1, label=val, group=Var3),
position=position_dodge2(width=1))+
facet_grid(Var1~Var2, scale="free_x")
Run Code Online (Sandbox Code Playgroud) 我的情节是可行的,除了我无法更改字体系列。即使我可以更改其他内容(例如颜色,大小和对齐方式),它也始终保持默认值。
这是我的代码:
ggplot(data = SeattleJuly17Data,
aes(x = Price, y = SatisfactionScore, col = RoomType)) +
geom_point() +
xlim(0,500) +
geom_smooth() +
ggtitle("Satisfaction Trends by Price and Room Type") +
theme(plot.title = element_text(family = "Calibri",
size=15,
color="Red",
hjust = 0.5)) +
xlab("Price per Night") +
ylab("Guest Satisfaction Score")
Run Code Online (Sandbox Code Playgroud) 我有奇数个图可以排列成一个图形,我希望显示以图形最后一行为中心的最后一个图。
这里有一些示例数据:
library(ggplot2)
set.seed(99)
x_1 = data.frame(z = rnorm(100))
x_2 = data.frame(z = rnorm(100))
x_3 = data.frame(z = rnorm(100))
lst = list(x_1, x_2, x_3)
lst_p = list()
for (i in 1:length(lst)) {
lst_p[[i]] = ggplot(data=lst[[i]], aes(lst[[i]]$z)) +
geom_histogram() +
xlab("X LAB") +
ylab("Y LAB")
}
p_no_labels = lapply(lst_p, function(x) x + xlab("") + ylab(""))
title = cowplot::ggdraw() + cowplot::draw_label("test", size = 20)
p_grid = cowplot::plot_grid(plotlist = p_no_labels, ncol = 2)
print(cowplot::plot_grid(title, p_grid,
ncol = 1, rel_heights = c(0.05, 1, 0.05))) …Run Code Online (Sandbox Code Playgroud) 我有一个包含每日流量的 csv 文件。我需要将每日值合并到每月中。我正在尝试使用“HydroTSM”包的“daily2monthly”功能。BRPT2.csv 中的示例数据:
_date,_time,_value,_flag
10/2/1959,0:00:00,0,2
10/3/1959,0:00:00,0,2
10/4/1959,0:00:00,1540,2
10/5/1959,0:00:00,16100,2
10/6/1959,0:00:00,6680,2
10/7/1959,0:00:00,3100,2
10/8/1959,0:00:00,2060,2
Run Code Online (Sandbox Code Playgroud)
我使用了以下命令:
qme<- read.csv(file = "BRPT2.csv",header = T,sep = ",") #read in csv file
date<- as.Date(qme$X_date,format("%Y-%m-%d")) #convert date column to date format from factor
flow<- qme[,3]
flow_2<-replace(flow,flow==-999,0) #replace the missing values (-999) with 0
df<- data.frame()
df<- rbind(df,data.frame(date,flow_2,stringsAsFactors = FALSE))
daily2monthly(df,FUN=sum,dates=1)
Run Code Online (Sandbox Code Playgroud)
它给出以下错误消息:
rownames<-( , value = c("Oct-1959", "Nov-1959", "Dec-1959",中的错误*tmp*:尝试在没有维度的对象上设置 'rownames'
有人可以帮我解决这个问题吗?提前致谢。
我正在尝试搜索数据库,然后"derived_name"在下面的可重现示例中使用从原始搜索派生的名称标记输出.我正在使用dplyr管道%>%,我在准静态评估和/或非标准评估方面遇到了麻烦.具体而言,使用在最终函数中count_colname派生自的字符对象无法对数据帧进行子集化."derived_name"top_n()
search_name <- "derived_name"
set.seed(1)
letrs <- letters[rnorm(52, 13.5, 5)]
letrs_count.df <- letrs %>%
table() %>%
as.data.frame()
count_colname <- paste0(search_name, "_letr_count")
colnames(letrs_count.df) <- c("letr", count_colname)
letrs_top.df <- letrs_count.df %>%
top_n(5, count_colname)
identical(letrs_top.df, letrs_count.df)
# [1] TRUE
Run Code Online (Sandbox Code Playgroud)
根据这个讨论,我认为上面的代码可行.而这篇文章引起我去尝试top_n_(),这似乎不存在.
我正在学习vignette("programming")哪个有点过头了.这篇文章让我尝试了!! sym()语法,这有效,但我不明白为什么!帮助理解为什么下面的代码工作将非常感激.谢谢.
colnames(letrs_count.df) <- c("letr", count_colname)
letrs_top.df <- letrs_count.df %>%
top_n(5, (!! sym(count_colname)))
letrs_top.df
# letr derived_name_letr_count
# 1 l 5 …Run Code Online (Sandbox Code Playgroud) 我在facet_grid()的帮助下创建了在ggplot中显示不同分数(0 - 100%)的饼图.然而,最后得分是结合其他得分的总得分,并且为了将其与其他得分更好地区分,我想更改该特定方面的参数.理想情况下,我想使facet-label变为粗体并将facet移动远离其他facet,但我不知道如何更改仅一个特定facet的参数.
library(ggplot2)
df <- data.frame(label = c("A", "B", "Total"), score = c(60, 70, 65))
ggplot(df, aes(x = "", y = score)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start=0) + scale_y_continuous(limits = c(0, 100)) +
facet_grid(. ~ label)
Run Code Online (Sandbox Code Playgroud)
我有这个原始数据集,下面是示例数据集:
X1 X2
1 Born 1946-05-27
2 bioguide A000370
3 Born 1979-06-19
4 bioguide A000371
5 Born 1980-04-18
6 bioguide A000367
7 Born 1958-06-12
8 bioguide A000369
9 Born 1948-03-23
10 bioguide B001291
Run Code Online (Sandbox Code Playgroud)
使用这个,我想要的输出如下:
Born biouguide
1 1946-05-27 A000370
2 1979-06-19 A000371
3 1980-04-18 A000367
4 1958-06-12 A000369
5 1980-04-18 A000367
Run Code Online (Sandbox Code Playgroud)
此外,以下是原始数据集的 dput:
structure(list(X1 = c("Born", "bioguide", "Born", "bioguide",
"Born", "bioguide", "Born", "bioguide", "Born", "bioguide"),
X2 = c("1946-05-27", "A000370", "1979-06-19", "A000371",
"1980-04-18", "A000367", "1958-06-12", "A000369", "1948-03-23",
"B001291")), row.names = c(NA, …Run Code Online (Sandbox Code Playgroud)