grid.arrange & ggplot2

Dear RStudio community

I am working on R Studio 2022.07.2
The aim is to combine to ggplot graphs using grid.arrange. In general it is working, but I am wondering a) why grid.arrange is not taking over colour definitions, axis and text configurations and b) how I can adapt grid.arrange .

  1. The two ggplots
    p2<-ggplot(data=BA2, aes(x=Jahr, y=Anteil, fill=Typ)) +
    geom_bar(stat="identity", position=position_dodge())
    p2 + labs(y = "Anteil BFF QII an der LN [%])", x="")+
    scale_fill_manual(values=c('darkgreen','red'))+
    theme_classic()+ theme(text = element_text(size = 18)) +
    scale_x_continuous(breaks=c(2015,2016,2017,2018,2019,2020))+
    ylim(0, 15)

p22<-ggplot(data=BA22, aes(x=Jahr, y=Anteil, fill=Typ)) +
geom_bar(stat="identity", position=position_dodge())
p22 + labs(y = "Anteil BFF QII an der BFF QI [%]", x="")+
scale_fill_manual(values=c('darkgreen','red'))+
theme_classic()+ theme(text = element_text(size = 18)) +
scale_x_continuous(breaks=c(2015,2016,2017,2018,2019,2020))+
ylim(0, 60)

  1. grid.arrange
    pA <- grid.arrange(p2, p22, ncol = 2)
    pA

It looks like when fill, axis, and text configurations are added, the plots are not being assigned to an object. Be sure to reassign p2 and p22 to the new configurations.

p2 <- ggplot(data=BA2, aes(x=Jahr, y=Anteil, fill=Typ)) +
geom_bar(stat="identity", position=position_dodge())

p2 <- p2 + labs(y = "Anteil BFF QII an der LN [%])", x="")+
  scale_fill_manual(values=c('darkgreen','red'))+
  theme_classic()+ theme(text = element_text(size = 18)) +
  scale_x_continuous(breaks=c(2015,2016,2017,2018,2019,2020))+
  ylim(0, 15)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.