0

I have three dataframes (saved in one list) which I plot individually as bar charts. The code for the plots look like this:

plot1 <- ggplot(list[[1]], aes_string(x = names(list[[1]])[[1]], y = "Kat")) + 
  geom_bar(stat = "identity", width = 0.6) + 
  ylim(0,100) +
  coord_flip() +
  guides(fill=FALSE) +
  theme_bw() + theme( strip.background  = element_blank(),
                      panel.grid.major = element_line(colour = "grey80"),
                      panel.border = element_blank(),
                      axis.ticks = element_blank(),
                      panel.grid.minor.y = element_blank(),
                      panel.grid.major.y = element_blank(),
                      axis.text.y = element_text(hjust = 0.5))

plot2 <- ggplot(list[[2]], aes_string(x = names(list[[2]])[[1]], y = "Kat")) + 
  geom_bar(stat = "identity", width = 0.6) + 
  ylim(0,100) +
  coord_flip() +
  guides(fill=FALSE) +
  theme_bw() + theme( strip.background  = element_blank(),
                      panel.grid.major = element_line(colour = "grey80"),
                      panel.border = element_blank(),
                      axis.ticks = element_blank(),
                      panel.grid.minor.y = element_blank(),
                      panel.grid.major.y = element_blank(),
                      axis.text.y = element_text(hjust = 0.5))


plot3 <- ggplot(list[[3]], aes_string(x = names(list[[3]])[[1]], y = "Kat")) + 
  geom_bar(stat = "identity", width = 0.6) + 
  ylim(0,100) +
  coord_flip() +
  guides(fill=FALSE) +
  theme_bw() + theme( strip.background  = element_blank(),
                      panel.grid.major = element_line(colour = "grey80"),
                      panel.border = element_blank(),
                      axis.ticks = element_blank(),
                      panel.grid.minor.y = element_blank(),
                      panel.grid.major.y = element_blank(),
                      axis.text.y = element_text(hjust = 0.5))

My goal is to arrange all three plots one below the other using grid.arrange That looks sth like this:

grid.arrange(plot1, plot1, plot3, ncol=1)

graphic output

However, since one of the plot has three bars and the other two have only 2 bars, the width of the bars is not the same when using grid.arrange. Therefore the question: How can maintain the size of the plots (or the width of the bars) using grid.arrange to display them in one below the other?

The list containing the three dataframes looks like this:

[[1]]
  Bildung Kat
2    Hoch  67
3 Mittel   50
4    Tief  25

[[2]]
  Geschlecht Kat
6          W  60
7          M  40

[[3]]
   Region Kat
9   Stadt  80
10   Land  70
lobo
  • 11
  • 3

1 Answers1

0

Maybe useing coord_equal() or coord_fixed() in all three plots will help?

Dr. Flow
  • 456
  • 5
  • 19