I try to make panel hights in facet_grid() to fit the plot - not be equal for every panel.
I found this: Different y-Axis Labels facet_grid and sizes Sadly it doesn't work :(
Here is my code, I'm using now
dane <- tibble(
"obszar" = c("Ludzie", "Ludzie", "Ludzie", "Ludzie",
"Myślenie", "Myślenie", "Myślenie",
"Zarządzanie", "Zarządzanie"),
"kompetencja" = c("Współdziałanie", "Komunikowanie i przekonywanie",
"Współdziałanie2", "Komunikowanie i przekonywanie2",
"Planowanie", "Wnioskowanie", "Innowacyjność",
"Budowanie zaangażowanego zespołu", "Inspirowanie i motywowanie"),
"wynik" = c(3,3,4,2,3,6,5,4,2),
"profil" = c(4,4,4,5,4,4,4,5,5)) %>%
mutate(luka = wynik - profil) %>%
arrange(obszar, kompetencja)
ggplot(dane, aes(x=kompetencja, y=wynik)) +
geom_segment(aes(x=kompetencja ,xend=kompetencja, y=1, yend=profil), color=kolor2) +
geom_point(aes(y = profil), pch = 19, size=3, color= kolor2) +
theme_bw() +
coord_flip(ylim=c(1,7)) +
theme(
legend.position = "none",
axis.text.x = element_text(size = 12),
axis.text.y = element_text(hjust = 1, size = 12),
panel.border = element_blank(),
axis.ticks=element_blank(),
axis.line.y = element_line(colour = "grey50"),
panel.grid.major.x = element_line(colour = "grey80", size = 0.2),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank()
) +
scale_y_continuous(breaks=seq(1,7,1)) +
labs(title = NULL,
caption = "źródło: opracowanie własne",
x = NULL,
y = NULL) +
annotate("rect", xmin = -Inf, ymin = 1, xmax = Inf, ymax = 2.5, fill = kolor2, alpha = 0.2) +
annotate("rect", xmin = -Inf, ymin = 5.5, xmax = Inf, ymax = 7.0, fill = kolor2, alpha = 0.2) +
facet_grid(obszar ~ ., scales = "free")
Output gives me 3 panels of hight equal to the highest one. I would like to get panels with heights adequate to the number of segments in the plot.