【发布时间】:2018-11-12 20:39:03
【问题描述】:
我正在尝试创建一个图表来跟踪多个因素的结果。理想情况下,我希望我的 xaxis 是 Day,天数位于特定日期的代表中间,y 轴是结果,而 facet 是 Lot (1-4)。我很难使用可重复的文本使一天以底部为中心,因为代表的数量可能会有所不同。
我正在使用这篇文章中显示的想法:Multi-row x-axis labels in ggplot line chart,但无法取得任何进展。
这是我一直在使用的一些代码以及到目前为止的情节。 x 轴太忙了,我正在尝试巩固它。
data <- data.frame(System = rep(c("A", "B"), each = 120), Lot = rep(1:4, each = 30),
Day = rep(1:5, each = 6), Rep = rep(1:6, 40), Result = rnorm(240))
library(ggplot2)
ggplot(data, aes(x = interaction(Day, Rep, lex.order = TRUE), y = Result, color = System, group = System)) +
geom_point() +
geom_line() +
theme(legend.position = "bottom") +
facet_wrap(~Lot, ncol = 1) +
geom_vline(xintercept = (which(data$Rep == 1 & data$Day != 1)), color = "gray60")
【问题讨论】: