1
votes

I have two questions regarding axis and facet labels in ggplot. I have searched around but failed to find exactly what I wanted.

I am using dotplots to graph treatment effects and confidence intervals for an electoral dataset featuring several sample disaggregation criteria (ie: coalition, office and (discontinuity). The data, and code for the plot follow:

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")

where the midpoint of the dotplot captures the "treatment" vector" and "upper" and "lower" give the upper and lower limits of the segments depicting confidence intervals. I am using ggplot and exploiting facet_wrap to disaggregate results by coalition (coded "1" and "2") and office .

My questions are:

1- How could I avoid redundancy in the labels so that the numbers 1 and 2 labelling coalitions could span across the four columns in each row?

2- How could I avoud redundancy in x-axis labels? (ie: to show axis labels only once for each column)

Any help will be much appreciated.

Thanks Luis

1

1 Answers

3
votes

Just replace facet_wrap with facet_grid and delete the ncol argument.