简体   繁体   中英

R Plot Bars are disappearing in grid.arrange/plot_grid

I have a problem with bars from my plots disappearing when I combine multiple plots.

Here is the code I´m using:

station<-c("Eins", "Zwei", "Drei","Vier")
x1<-c(200, 185, 165,180)
x2<-c(185,150,148,25)
x3<-c(156,125,141,36)

test.data<-data.frame(station,x1,x2,x3)


plot_sof<-ggplot(test.data, aes(x=station, y=x1))
plot_sof + geom_bar(stat="identity",na.rm=TRUE)

plot_sof_1<-ggplot(test.data, aes(x=station, y=x2))
plot_sof_1+geom_bar(stat = "identity",na.rm=TRUE)

plot_sof_2<-ggplot(test.data, aes(x=station, y=x3))
plot_sof_2+geom_bar(stat = "identity",na.rm=TRUE)

plot_grid(plot_sof, plot_sof_1, plot_sof_2, labels=c("x1", "x2", "x3"))

grid.arrange(plot_sof, plot_sof_1, plot_sof_2, ncol=1)```

应合并的地块之一的示例

首先尝试通过 grid.arrange 组合图,缺少条

通过 plot_grid 进行第二次尝试,这里的条形图也不见了

Does anyone know why the bars are missing and maybe know a solution or a workaround for that problem?

Try with this, you have to assign the new geom to your objects:

#Code
plot_sof<-ggplot(test.data, aes(x=station, y=x1))
plot_sof <-plot_sof + geom_bar(stat="identity",na.rm=TRUE)

plot_sof_1<-ggplot(test.data, aes(x=station, y=x2))
plot_sof_1 <- plot_sof_1+geom_bar(stat = "identity",na.rm=TRUE)

plot_sof_2<-ggplot(test.data, aes(x=station, y=x3))
plot_sof_2 <- plot_sof_2+geom_bar(stat = "identity",na.rm=TRUE)

plot_grid(plot_sof, plot_sof_1, plot_sof_2, labels=c("x1", "x2", "x3"))

grid.arrange(plot_sof, plot_sof_1, plot_sof_2, ncol=1)

Outputs:

在此处输入图像描述

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM