R 移动ggplot中文本的位置

R 移动ggplot中文本的位置,r,ggplot2,boxplot,R,Ggplot2,Boxplot,希望这是一个非常简单的问题需要解决-我已经用下面的代码生成了图中的箱线图 ggplot(minanalysis, aes(x=MinAnaType, y=Calcium)) + geom_boxplot() + geom_point(aes(colour=Ploidy)) + stat_summary(fun.y=mean, colour="black", geom="point", size=2,show.legend = FALSE) + geom_text(data =

希望这是一个非常简单的问题需要解决-我已经用下面的代码生成了图中的箱线图

ggplot(minanalysis, aes(x=MinAnaType, y=Calcium)) +
  geom_boxplot() +
  geom_point(aes(colour=Ploidy)) +
  stat_summary(fun.y=mean, colour="black", geom="point", size=2,show.legend = FALSE) + 
  geom_text(data = means, vjust = -0.25, hjust=-0.3, size = 3, aes(label = round(Calcium, 2), 
                                                   y = Calcium + 0.08)) +
  #add a sample size n =
  geom_text(data = minanalysis %>% group_by(MinAnaType) %>% 
          summarize(Count = n(), 
          Calcium=max(Calcium) + 0.05 * diff(range(minanalysis$Calcium))),
          aes(label = paste0("n = ", Count)), 
          position = position_dodge(0.85), size=3, show.legend = FALSE) +
  # Add pairwise comparisons p-value and global p-value
  stat_compare_means(comparisons = my_comparisons, label = "p.signif", label.y = 9500, size = 4) + 
  stat_compare_means(label.y = 10500, size = 4)    
我想要的是将“n=290”和“n=50”放在x轴标签“去内脏”和“全身”的下方。将它们放在方框图上方太乱了。有人能帮我编写代码吗,我是R studio的新手


谢谢

最简单的方法可能是在x标签上添加换行符。然后您可以添加计数,可以是硬编码的,也可以是编程的。 (这将在
比例范围内(标签=…)

例如

库(tidyverse)
ggplot(滤镜(鸢尾属,种%,%c('setosa','virginica')),aes(种,萼片长度))+
geom_箱线图()+
缩放x离散(标签=c(setosa=paste('setosa','\nn=30'),
virginica=粘贴('virginica','\nn=30'))

你应该能够使用——被接受的答案已经有8年历史了,所以现在在第二高投票率的答案中使用解决方案要容易得多。你使用的是ggpubr,对吗?嗨,是的,我使用的是ggpubrHi Tjebo,谢谢你的回复,但不幸的是,我不知道如何使你的解决方案适应我上面的代码。@HarryH-W请阅读
https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-repeatable-example
。如果您不提供这样的工作示例,很难为您提供帮助