简体   繁体   中英

Plot several graphs in R

I am trying to plot automatically several graphs with ggplot. I want to make a total of 23 stacked bar plot.

The original df ( train2016 ) has variables in columns 25 to 48 and all of them have the values c(0, 1) .

I want to represent on Y axis the month (given in a column) - X axis the result of the count of 0 or 1 value of each variable.

I cannot see the result and there is no error showing. This is the code I wrote. I know there must be multiple errors

par(nfrow=c(4,6))
for (i in 25:48) {
  datos22 <- train2016 %>%
    group_by(month, train2016[i]) %>%
    summarise(count= n()) %>% 
    ggplot(aes(fill=train2016[i], x=count,y=month)) +
    geom_col() +
    ggtitle(" ") 
}

You can try ggsave to save the graphs

par(nfrow=c(4,6))

for (i in 25:48) {
  datos22 <- train2016 %>%
    group_by(month, train2016[i]) %>%
    summarise(count= n()) %>% 
    ggplot(aes(fill=train2016[i], x=count,y=month)) +
    geom_col() +
    ggtitle(" ") 
  ggsave(paste0("plot_", i, ".png")) 
}

Will save all the plots to independent files.

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