如何使用 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() 的相同代码时,它起作用了。


当我可以避免错误时,新的问题来了。我粘贴了我创建的图形。许多注释已经出现在一个图中。在此处输入图像描述

乔恩·斯普林

正如@stefan 所指出的,您的文本层的数据应该引用 faceting 变量:

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  facet_wrap(~am) +
  geom_text(data = data.frame(wt = 2, mpg = c(30, 12), am = c(0,1),
                              label = c("one note", "and another")),
            aes(label = label))

在此处输入图像描述

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用相同 facet_wrap 的不同变量的多个箱线图

ggplot在使用`facet_wrap`时添加正态分布

使用 facet_wrap 时 x 轴上的数据移位

如何使用facet_wrap拆分列并绘制图形?

如何为使用facet_wrap创建的图添加单独的ggplot标题?

如何使用facet_wrap将NSE和PBIAS结果添加到ggplot中?

在`ggplot`和`ggmap`中使用`facet_wrap`来显示多个图形的问题

在Y轴缩放比例不同的ggplot中使用facet_wrap时使用双y轴

使用带有 facet_wrap 的 ggplot 使用不同类型的 lynes

如何在 facet_wrap 中在两个不同类别之间绘制国家/地区?

在 ggplot/facet_wrap() 中,如何标记 Y 轴有不同的格式

使用ggplot2和facet_wrap显示不同的轴标签

使用facet_wrap时,geom_bar中的条具有不同的宽度

在ggplot2中,如何在facet_wrap中按组添加文本?

如何向 facet_wrap(ed) geom_count 图添加标签?

如何在ggplot facet_wrap文本中添加数学符号?

如何在此自定义facet_wrap中添加geom_quantile图例?

使用 facet_wrap 时无法向 geom_text 添加条件

使用facet_wrap将图例添加到ggplot中

使用facet_wrap在ggplot中添加唯一轴标签名称

将累积数量添加到使用facet_wrap绘制的geom_bar图中

使用 R 在 facet_wrap 上以 chr 类型格式化 x 轴日期

使用facet_wrap显示多个直方图

ggplot 在 R 中使用 facet_wrap?

使用facet_wrap()时颜色错误

facet_wrap添加geom_hline

如何使用facet_wrap产生的空白空间?

当与facet_wrap()一起使用时,为什么geom_rect()添加许多多层?

使用相同的构面数据向每个facet_wrap添加一个子图