R语言 在ggplot中调整y刻度

rxztt3cl  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(139)

我想调整y刻度,它应该从5开始,在-5结束,并从这个刻度中删除所有数据点我试过这个代码

pd = position_dodge(width = 0.5)
ggplot(dt, aes(fill=Treatment, y= value, x=variable)) +
  stat_boxplot(geom = "errorbar",width = 0.25, position = pd)+
  geom_boxplot(width=0.4, position = pd, outlier.shape = NA)+ 
  geom_jitter(position = position_jitterdodge(jitter.width = 0.2,jitter.height = 0.8,dodge.width=0.5),
              shape=21, size=0.3, alpha=0.3) +
  scale_fill_manual(values = c("#CF9FFF","#800080"))+
  stat_compare_means(aes(group = Treatment),method = "anova", label = "p.signif",
                     label.y = c(2.15,2.55,2.7,2.3,2.7,2.7),size=3.5,
                     symnum.args = list(cutpoints = c(0,0.001, 0.01, 0.05, Inf),
                                        symbols=c("***","**","*","ns")))+
  theme(axis.text.x = element_text(size = 10, colour = "black", face="bold"),
        axis.text.y = element_text(size = 10, colour = "black", face="bold"),
        legend.position = c(0.15, 0.05), legend.background = element_blank(),
        legend.direction = "horizontal", legend.title = element_blank(),
        legend.text = element_text(size = 9, face="italic", colour = "black")) + 
  scale_y_continuous(breaks = seq(-5,5,1),labels = number_format(accuracy = 0.01))


但它创建了这个图。

ovfsdjhp

ovfsdjhp1#

只是上面的一个注意-如果你使用coord_carlass(ylim=c(ymin,ymax)),它会放大数据,
scale_y_continuous(limits = c(ymin,ymax))
所以如果这是你想做的,
你实际上删除了范围之外的数据,这将改变你的箱形图......一种去除异常值的方法,

相关问题