【发布时间】:2021-12-30 19:39:55
【问题描述】:
我创建了一个条形图来显示不同地点和层的积水差异。因为一个值远高于其他值,所以我想将 y 轴设置为 log10 刻度。这一切都有效,但结果看起来相当不直观。是否可以将 y 轴的限制设置为 0,以使值为 0.2 的条不向下?
这是我使用的代码:
p2 <- ggplot(data_summary2, aes(x= Site, y= small_mean, fill= Depth, Color= Depth))+
geom_bar(stat = "identity", position = "dodge", alpha=1)+
geom_errorbar(aes(ymin= small_mean - sd, ymax= small_mean + sd),
position = position_dodge(0.9),width=0.25, alpha= 0.6)+
scale_fill_brewer(palette = "Greens")+
geom_text(aes(label=small_mean),position=position_dodge(width=0.9), vjust=-0.25, hjust= -0.1, size= 3)+
#geom_text(aes(label= Tukey), position= position_dodge(0.9), size=3, vjust=-0.8, hjust= -0.5, color= "gray25")+
theme_bw()+
theme(legend.position = c(0.2, 0.9),legend.direction = "horizontal")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
labs(fill="Depth [cm]")+
theme(axis.text.x = element_text(angle = 25, size =9, vjust = 1, hjust=1))+
scale_x_discrete(labels= c( "Site 1\n(Hibiscus tillaceus)","Site 2 \n(Ceiba pentandra)","Site 3 \n(Clitoria fairchildiana)","Site 4 \n(Pachira aquatica)"))+
#theme(legend.position = c(0.85, 0.7))+
labs(x= "Sites\n(Type of Tree)", y= "µg Deep-Water/ g rhizosphere soil", title = "Average microbial Deep-water incorporation per Site", subtitle = "Changes over Time and Depth")+
facet_grid(.~Time, scale = "free")
p2 + scale_y_continuous(trans = "log10")
剧情是这样的:
【问题讨论】:
-
欢迎来到 SO,Umberto_Leckerbaer!请让这个问题可重现。这包括您尝试过的示例代码(包括列出非基础 R 包以及收到的任何错误/警告)、示例明确数据(例如,
data.frame(x=...,y=...)或来自dput(head(x))的输出),和给定输入的预期输出。参考:stackoverflow.com/q/5963269、minimal reproducible example 和 stackoverflow.com/tags/r/info。 -
试试:
scale_y_continuous(trans = "log", breaks = c(0, 1, 10, 100), limits = c(NA, 100)) -
对数刻度中小于 1 的分数是什么?这些是负值,所以我发现这实际上比试图将它们显示为正值更直观。此外,您显示配对数据(第 3 天和第 10 天的测量值),也许可以考虑使用散点图。将更好地显示变化。很想展示如何,但如果没有一些虚假数据是不可能的。
-
请提供足够的代码,以便其他人更好地理解或重现问题。