如何使用Facet_wrap在数字上添加不同的注释
我想对facet_wrap产生的数字添加不同的注释。
我尝试了以下代码,但是它显示出错误,例如“ fun中的错误(x [i],...):对象'值'未找到”。
dat_text <- data.frame(
label = c("TRUE:FALSE = 686:324", "TRUE:FALSE = 976:34", "TRUE:FALSE = 516:494", "TRUE:FALSE = 360:650",
"TRUE:FALSE = 351:659", "TRUE:FALSE = 440:570", "TRUE:FALSE = 645:365", "TRUE:FALSE = 151:859", "TRUE:FALSE = 542:468"),
cyl = c(Agricultural_land, Artificial_land, Precipitation, Protected_area,
RiverLake, Seashore, Temperature, Volcanic_area, Wasteland)
)
z_cor <- fit01_zsize2 %>%
ggplot(aes(x = value_without, y = value_with, color = value))+
geom_point(shape = 1)+
geom_text(
data = dat_text,
mapping = aes(x = -Inf, y = -Inf, label = label),
hjust = -0.1,
vjust = -1
)+
geom_abline(intercept = 0, slope = 1, linetype = "dashed") +
scale_color_manual(values = c("TRUE" = "salmon", "FALSE" = "steelblue"))+
facet_wrap(.~variable1)+
theme(strip.text.x = element_text(size = 20),
axis.title=element_text(size=16))
plot(z_cor)
当我在没有GEOM_TEXT()的情况下尝试相同的代码时,它起作用。
I would like to add different annotations on figures produced by facet_wrap.
I tried the below code, but the it showed error such as "Error in FUN(X[[i]], ...) : object 'value' not found".
dat_text <- data.frame(
label = c("TRUE:FALSE = 686:324", "TRUE:FALSE = 976:34", "TRUE:FALSE = 516:494", "TRUE:FALSE = 360:650",
"TRUE:FALSE = 351:659", "TRUE:FALSE = 440:570", "TRUE:FALSE = 645:365", "TRUE:FALSE = 151:859", "TRUE:FALSE = 542:468"),
cyl = c(Agricultural_land, Artificial_land, Precipitation, Protected_area,
RiverLake, Seashore, Temperature, Volcanic_area, Wasteland)
)
z_cor <- fit01_zsize2 %>%
ggplot(aes(x = value_without, y = value_with, color = value))+
geom_point(shape = 1)+
geom_text(
data = dat_text,
mapping = aes(x = -Inf, y = -Inf, label = label),
hjust = -0.1,
vjust = -1
)+
geom_abline(intercept = 0, slope = 1, linetype = "dashed") +
scale_color_manual(values = c("TRUE" = "salmon", "FALSE" = "steelblue"))+
facet_wrap(.~variable1)+
theme(strip.text.x = element_text(size = 20),
axis.title=element_text(size=16))
plot(z_cor)
When I tried the same code without geom_text(), it worked.
When I could avoid the error, the new problem has come.
I pasted the figure I created. Many annotations has come in a figure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@stefan所指出的那样,您的文本层的数据应引用faceTing变量:
As @stefan noted, your text layer's data should reference the faceting variable: