我有两个关于 ggplot 中的轴和构面标签的问题。我四处寻找,但没有找到我想要的东西。
我正在使用点图来绘制一个选举数据集的处理效果和置信区间,该数据集具有几个样本分解标准(即:联盟、办公室和(不连续性))。该图的数据和代码如下:
treatment<- c(0.0575991, 0.0679221, 0.4750282, 0.5264731, 0.649701, 0.4012088, 0.8792834, 0.7785651, -0.0523253, 0.302815, 0.0200715, 1.12161, 0.2174055, -0.7917859, 0.053338, -0.8650882, 0.060367, 0.0688683, 0.4708295, 0.5074752, 0.3618211, 0.2811037, 0.7121391, 0.3285163, -0.1002695, 0.4352929, -0.1790575, 0.7706336, 0.2003012, 0.5434131, -0.0008607, 0.5872229)
window <- c(2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5)
office <- c("Local Council", "Local Council", "Local Council", "Local Council", "Lower Chamber", "Lower Chamber","Lower Chamber", "Lower Chamber", "Mayor", "Mayor", "Mayor", "Mayor", "Senate", "Senate", "Senate", "Senate", "Local Council", "Local Council", "Local Council", "Local Council", "Lower Chamber", "Lower Chamber", "Lower Chamber", "Lower Chamber", "Mayor", "Mayor", "Mayor", "Mayor", "Senate", "Senate", "Senate", "Senate")
coalition <- c(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2)
upper <- c(0.0775991, 0.0879221, 0.5550282, 0.6464731, 0.909701, 0.9412088, 1.2792834, 1.4185651, 0.2276747, 0.602815, 0.4400715, 2.26161, 2.9374055, 5.2482141, 2.013338, 9.4549118, 0.060367, 0.0888683, 0.5508295, 0.6074752, 0.6018211, 0.6011037, 0.9921391, 0.8285163, 0.5197305, 0.7552929, 6.4009425, 1.4106336, 0.8203012, 1.8034131, 0.7791393, 1.8072229)
lower <- c(0.0375991, 0.0479221, 0.3950282, 0.4064731, 0.389701, -0.1387912, 0.4792834, 0.1385651, -0.3323253, 0.00281500000000001, -0.3999285, -0.0183899999999999, -2.5025945, -6.8317859, -1.906662, -11.1850882, 0.060367, 0.0488683, 0.3908295, 0.4074752, 0.1218211, -0.0388963, 0.4321391, -0.1714837, -0.7202695, 0.1152929, -6.7590575, 0.1306336, -0.4196988, -0.7165869, -0.7808607, -0.6327771)
df <- data.frame(treatment, as.factor(window),office, coalition, upper, lower)
ggplot(data = df, mapping = aes(x = as.factor(window), y= treatment))+geom_pointrange( data = df, stat = "identity",
mapping = aes(ymin= lower,ymax=upper))+facet_wrap(coalition ~ office, ncol=4, scales = "free")
其中点图的中点捕获“处理”向量”,“上限”和“下限”给出描述置信区间的段的上限和下限。我正在使用 ggplot 并利用 facet_wrap 按联盟分解结果(编码为“1 "和 "2") 和办公室。
我的问题是:
1- 我怎样才能避免标签中的冗余,以便数字 1 和 2 标签联盟可以跨越每行的四列?
2- 如何避免 x 轴标签中的冗余?(即:每列仅显示一次轴标签)
任何帮助都感激不尽。
谢谢路易斯