嵌套分组变量的标签

Labels for nested grouping variables

提问人:Rylee Swiderek 提问时间:8/3/2023 最后编辑:zephrylRylee Swiderek 更新时间:8/3/2023 访问量:33

问:

我希望将它们放在每个条形下方的 x 轴上,而不是将每个处理的标签放在图例上。这是我的代码,我非常满意:

fillggp <- ggplot(corn_germ, aes(x=Day, y=PercentGermination, fill = Treatment)) + geom_bar(stat= "identity",position = position_dodge(), colour= "black") + 
  theme_classic() + 
  theme(axis.title.x = element_text(color="black", size=12, margin = margin(t=10)),axis.title.y = element_text(color="black", size=12, margin = margin(r = 10)))

fillggp <- fillggp + scale_y_continuous(breaks= pretty_breaks(), limits=c(0, 1.2)) + labs(x ="Day", y = "Percent Germination")
fillggp

产生情节

但同样,我希望治疗名称正好出现在其相应的条形下方,而不是图例。

我试过使用facet_grid但生成的图表每天分组到治疗中,这与我想要的相反

fillggp +
  facet_grid(~Treatment, switch = "x", scales = "free_x", space = "free_x") +
  theme(panel.spacing = unit(0, "lines"), 
        strip.background = element_blank(),
        strip.placement = "outside") 

R ggPlot2 嵌套 条形图

评论

1赞 zephryl 8/3/2023
交换 和 — 即映射到 in ,然后由 facet by 。DayTreatmentTreatmentxaes()~Day
0赞 Rylee Swiderek 8/3/2023
谢谢,奏效了!有没有办法旋转嵌套文本,使其不重叠?现在,治疗名称被捆绑在一起。

答: 暂无答案