首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何解决ggplot和ggsignif的问题

如何解决ggplot和ggsignif的问题
EN

Stack Overflow用户
提问于 2021-11-20 22:27:13
回答 2查看 77关注 0票数 0

我试着成对地画出不同之处。我在这个论坛上找到了一个示例,但我想使用geom_signif函数在此图中添加重要级别信息。不幸的是,我得到的信息是:"Error in f (...):只能处理x轴上绘制的组的数据“,有人能帮我解决这个问题吗?

代码语言:javascript
运行
复制
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())
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-21 02:30:21

我认为您需要做的是安装ggh4x。它是ggplot2的一个插件,具有一些有用的工具,例如在您的情况下正确添加刻度和次要刻度。一旦你加载了R包,你就可以开始工作了。

编辑:

出现该错误的原因是没有为ggsignif指定group()

代码语言:javascript
运行
复制
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())

票数 0
EN

Stack Overflow用户

发布于 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注释。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70050351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档