0

Cant not arrange barplots in one page

p3<-barplot(Fehleranzahl_aktuell$Anzahl_Fehler,names.arg=Fehleranzahl_aktuell$Ursachentext,col=c("blue"),xlab="Anzahl Fehler",horiz = TRUE,
        las=2,las=1,top = "Fehler aktuelle Buchungsperioden",xlim=c(0,Anzahl_Max))

Anzahl_Max=max(Fehleranzahl$Anzahl_Fehler)


p4<-(barplot(Fehleranzahl$Anzahl_Fehler,names.arg=Fehleranzahl$Ursachentext,col=c("blue"),xlab="Anzahl Fehler",horiz = TRUE,
        las=2,las=1,main = "Kumulierte Fehler 12 Buchungsperioden",xlim=c(0,Anzahl_Max+5)))

grid.arrange(p1, p2, nrow = 2)

I get to following error:

Error in plot_to_gtable(x) : Argument needs to be of class "ggplot", "gtable", "grob", "recordedplot", or a function that plots to an R graphicsdevice when called, but is a matrix

RLave
  • 8,144
  • 3
  • 21
  • 37
  • 1
    There seems to be a typo, you call `p1`, `p2` but the names are `p3` and `p4`. Also please make your problem reproducible. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – RLave Jan 21 '19 at 08:26

1 Answers1

2

The problem here I believe is that you are trying to combine base R plots with a function that combines ggplots.

Also I am not sure that you can save base R plots like barplot() to an object in this way.

To combine plots in base R you can use;

par(mfrow=c(2, 1))

Write this line before your barplots.

Alternatively to use grid.arrange() convert the base R barplots to ggplot barplots.

ggplot(data, aes()) + geom_bar()
Adam Waring
  • 1,158
  • 8
  • 20