我正在使用一个嵌套的框图来比较观察到的地貌类型和模拟的地貌类型。我希望将每个数据集的均值显示为每个箱线图框内的一条线(而不是一个点)。
为了擦除中间线,并将均值作为"errorbar“输入,我使用了以下代码:
No.Forest.Plot <- ggplot(data = NoForest_Long,
aes(x= value, y = variable, fill = ObsSim)) +
labs(x= "Percent of Cover", y= "Land Type Categories") +
ggtitle( "Observed vs. Simulated Land Categories (No Forest)") +
geom_boxplot(fatten = NULL) +
stat_summary(fun = mean, fun.min = mean,
fun.max = mean, geom = "errorbar", width = 0.5,) 它提供了this图。不幸的是,线条位于每个类别的中心,而不是框本身。
我如何让“观察”和“模拟”的方法在各自的框中居中?
发布于 2021-06-19 03:14:27
这可以通过设置errorbar的position来实现。因为geom_boxplot默认使用position_dodge(.75),所以你也必须对你的errorbar使用相同的position。
使用mtcars作为示例数据:
library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = factor(cyl), fill = factor(am))) +
geom_boxplot(fatten = NULL) +
stat_summary(fun = mean, fun.min = mean,
fun.max = mean, geom = "errorbar", position = position_dodge(.75), width = .7)

https://stackoverflow.com/questions/68039392
复制相似问题