我试着成对地画出不同之处。我在这个论坛上找到了一个示例,但我想使用geom_signif函数在此图中添加重要级别信息。不幸的是,我得到的信息是:"Error in f (...):只能处理x轴上绘制的组的数据“,有人能帮我解决这个问题吗?
d <- data.frame(y = rnorm(20, 9, 2),
group = as.factor(rep(c('Post-FAP', 'Post-DEP'), each = 10)),
id = rep(1:10, 2))
ggplot(d, aes(y = y)) +
geom_boxplot(aes(x = rep(c(-2.5, 2.5), each = 10), group = group), fill = '#47E3FF') +
geom_point(aes(x = rep(c(-1, 1), each = 10)), shape = 21, size = 1.5, col = "black", fill = "grey") +
geom_line(aes(x = rep(c(-1, 1), each = 10), group = id)) +
#geom_signif(annotation = "p=0.05", y_position = 13, xmin = -2.5, xmax = 2.5, tip_length = .02) +
scale_x_continuous(breaks = c(-2.5, 2.5), labels = c("Post-FAP", "Post-DEP")) +
scale_y_continuous(minor_breaks = seq(5, 14, by =1),
breaks = seq(6, 14, by = 2), limits = c(5, 14),
guide = "axis_minor") +
theme_bw() +
theme(legend.position = "none", panel.grid = element_blank())
发布于 2021-11-21 02:30:21
我认为您需要做的是安装ggh4x
。它是ggplot2
的一个插件,具有一些有用的工具,例如在您的情况下正确添加刻度和次要刻度。一旦你加载了R包,你就可以开始工作了。
编辑:
出现该错误的原因是没有为ggsignif
指定group()
library(ggh4x)
library(ggplot2)
library(ggsignif)
ggplot(d, aes(y = y)) +
geom_boxplot(aes(x = rep(c(-2.5, 2.5), each = 10), group = group), fill = '#47E3FF') +
geom_point(aes(x = rep(c(-1, 1), each = 10)), shape = 21, size = 1.5, col = "black", fill = "grey") +
geom_line(aes(x = rep(c(-1, 1), each = 10), group = id)) +
geom_signif(d, mapping = aes(x=id, y=y,group=group),annotation = "p=0.05", y_position = 13, xmin = -2.5, xmax = 2.5, tip_length = .02) +
scale_x_continuous(breaks = c(-2.5, 2.5), labels = c("Post-FAP", "Post-DEP")) +
scale_y_continuous(minor_breaks = seq(5, 14, by =1),
breaks = seq(5, 14, by = 2), limits = c(5, 14),
guide = "axis_minor") +
theme_bw() +
theme(legend.position = "none", panel.grid = element_blank())
发布于 2021-11-20 23:14:00
在您发布的错误消息上有一个线程here,表示aes (x和y)上的所有信息都需要由子函数访问,即geom_signif
。
使用ggplot(d, x=aes(as.numeric(group), y=y, group = group))
对我很有效。
有趣的是,ggplot(d, x=aes(rep(c(-2.5, 2.5), each = 10), y=y, group = group))
没有返回错误,也没有显示geom_signif
注释。
https://stackoverflow.com/questions/70050351
复制相似问题