我试图创建一个使用图表facet_wrap与facet_grid内每个包裹面,但我不能.有什么建议?
例如,如果我按月平均2个数量进行年度比较,我希望 -
我能来的最近的是这个,
library(ggplot2)
# create dataset
df <- data.frame(
Facet1 = rep(c(1,2,3),24),
Facet2 = c(rep(1,24),rep(2,24)),
Year = rep(c(rep(2012,12),rep(2013,12)),2),
Month = rep(rep(1:12,2),2),
ValueX = sample(0:5,144,replace = TRUE),
ValueY = sample(0:5,144,replace = TRUE)
)
df <- df[!(df$Facet1 == 2 & df$Facet2 == 2),]
ggplot(df, aes(ValueX, ValueY)) + geom_point() +
facet_grid(Facet2 + Year ~ Month)
Run Code Online (Sandbox Code Playgroud)

虽然,我理想的是,这是符合这一点的(在我看来,类似于ggplot() ... + facet_grid(Year ~ Month) + facet_wrap(Facet2~.)) -

PS:我认为后者的各个方面更容易区分和更整洁.评论?任何替代品?
也许我误解了你想要做什么,但这没有达到你想要的效果吗?
ggplot(df, aes(ValueX, ValueY)) + geom_point() +
facet_grid(Facet2 ~ Facet1)
Run Code Online (Sandbox Code Playgroud)
如果您想更改方面标题以匹配您的示例,请查看 的labeller参数facet_grid()。