【发布时间】:2020-04-07 13:42:11
【问题描述】:
我想更改我的 ggplot Boxplot 的顺序和实验室。 这是我目前所拥有的:
ggplot(total_nr_obj_week_corr.3, aes(x=distance, y=n)) +
stat_boxplot(geom = "errorbar")+
geom_boxplot()+
facet_wrap(~year_month, strip.position = "bottom",scales = "free", nrow=2)+
scale_y_continuous(expand = c(0,0),limits = c(0, 70), breaks = seq(0, 80, by = 10)) +
scale_x_discrete(limits = c("0", "5","10", "15","20"), breaks = c("0", "5","10", "15","20"))+
theme(strip.placement="outside",
strip.background = element_rect(color="black",
fill="white",size = rel(1)),
axis.title.x = element_text(margin = margin(t = 10, r = 0 , b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 10 , b = 0, l = 0)))
这是我的阴谋
我想改变不同面的位置。 第一排 2017 05-08 第二行 2018 05-09
我在 facet_wrap() 中尝试了 as.table = F,但仍然没有得到正确的顺序。
其次,我想更改标签。 在 x 轴下方,我想要月份(05-08/09),在大标签上的每一行上方,每行带有年份(2017/2018)。
我用谷歌搜索了几个小时,但找不到解决方案。我也试过fact_grid,但不是我想要的结果
谢谢!!
【问题讨论】:
-
因为它是not a reproducible example,所以我无法添加特定的代码来提供帮助,但要更改
facet_wrap,您可以将year_month转换为与您的首选排序相对应的级别的因子。创建factor时,您还可以添加labels参数,这将有助于在每个方面提供年份标签see here。
标签: r ggplot2 boxplot facet facet-wrap