I plot the estimates of six countries using facet_wrap. I would like to add one layer and divide the countries into two groups a
and b
while keeping the facet_wrap option. This means that i would like to see the plots separated by each country in both groups a
and b
.
Here is the plot when all countries are together:
df %>%
ggplot(aes(x= estimate, y=term)) +
geom_point(mapping=aes(x=estimate, y=term)) +
facet_wrap( ~ cntry, strip.position = "bottom")
I try to separate them using ggforce
. As we can see, it does in fact separate them but in fact all countries become mixed in one plot. Is there a way to keep each country plotted alone while being in two different groups?
Here is the code and the plot:
df %>%
ggplot(aes(x= estimate, y=term)) +
geom_point(mapping=aes(x=estimate, y=term)) +
facet_wrap( ~ cntry, strip.position = "bottom") +
ggforce::facet_row(vars(cat_f), scales = 'free_x', strip.position = 'bottom')
Here is the data:
structure(
list(
cntry =
structure(
c("Austria", "Belgium", "Italy", "Switzerland", "Spain", "Austria","Belgium", "Italy", "Switzerland", "Spain", "Denmark"),
format.stata = "%15s"
),
estimate =
structure(
c(1, 1.5, 2, 1.20000004768372, 1.70000004768372, 4, 5.5, 6, 3, 3.09999990463257, 4.30000019073486),
format.stata = "%8.0g"
),
cat_f =
structure(c("Widening gap",
"Widening gap", "Widening gap", "Widening gap", "Widening gap",
"No change", "No change", "No change", "No change", "No change",
"No change"),
format.stata = "%13s"
),
term =
structure(c("2009", "2009", "2009", "2009", "2009", "2008", "2008", "2008", "2008", "2008", "2008"),
format.stata = "%15s"
)
),
row.names = c(NA, -11L),
class = "data.frame"
)