so I have a simple example--a fully crossed three treatmentthree context experiment, where a continuous effect was measured for each treatmentcontext pair. I want to order each treatment by effect, separately according for each context, but I'm stuck on ggplot's faceting.
here's my data
df <- data.frame(treatment = rep(letters[1:3], times = 3),
context = rep(LETTERS[1:3], each = 3),
effect = runif(9,0,1))
and I can get something very close if I collapse treatment and context into a single 9 point scale, as such:
df$treat.con <- paste(df$treatment,df$context, sep = ".")
df$treat.con <- reorder(df$treat.con, -df$effect, )
ggplot(df, aes(x = treat.con, y = effect)) +
geom_point() +
facet_wrap(~context,
scales="free_x",
ncol = 1)
except to achieve the separate ordering in each facet, the new x variable I created is potentially misleading, since it doesn't demonstrate that we've used the same treatment in all three contexts.
Is this solved via some manipulation of the underlying factor, or is there a ggplot command for this situation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…