我对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")
其中dotplot的中点捕获&#34;处理&#34;矢量&#34;和 &#34;上部&#34;并且&#34;降低&#34;给出描绘置信区间的段的上限和下限。 我正在使用ggplot并利用facet_wrap按联盟分解结果(编码&#34; 1&#34; 和&#34; 2&#34;)和办公室。
我的问题是:
1-如何避免标签中的冗余,以便数字1和2标记联盟可以跨越每行的四列?
2-我怎样才能在x轴标签中实现冗余? (即:仅显示轴标签一次 对于每一栏)
非常感谢任何帮助。
由于 路易斯
答案 0 :(得分:3)
只需将facet_wrap
替换为facet_grid
,然后删除ncol
参数。