在R中使用多面换行来格式化500多个图的最佳方法?[图像和包括代码] [英] Best way to format 500+ plots using facet wrap in R? [images & code included]

查看:62
本文介绍了在R中使用多面换行来格式化500多个图的最佳方法?[图像和包括代码]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图显示890个供应商的每周(x轴)销售额(y轴).我想使用多面包装显示这些数据,以快速查看供应商的销售量激增的地方.我的RStudio控制台中的图看起来像这样.这是有道理的,因为在此处渲染图并不是最好的视图,但是,即使需要多页PDF,我如何才能将图正确格式化为PDF.情节代码

I am trying to display sales (y-axis) week over week (x-axis) for 890 vendors. I want to display this data using a facet wrap to quickly see where vendors are having a spike in sales. The plot in my RStudio console looks as such. This Makes sense, as rendering the plot here isnt the best view, however how can I properly format my plots onto a PDF even if it requires multiple pages of PDFs. Code for plot

ggplot(Holiday_Spike_Table, aes(x = FSCL_WK, y = SLS))+ 
  geom_col()+
  facet_wrap(~MVNDR_NM)

推荐答案

以下是制作多个页面的方法-每个页面都有5x5的供应商.

Here's how to make multiple pages - each with 5x5 vendors.

我将与890个供应商一起使用一些虚拟数据.

I'll use some dummy data with 890 vendors.

library("tidyverse")

df <- data.frame(
  vendor = rep(seq_len(890), each = 30) ,
  x = rep.int(seq_len(30), 890),
  y = runif(890 * 30),
  group = (rep(seq_len(890), each = 30) - 1) %/% 25
)

分成25个吠叫组.每个情节都有一个5x5的构面.

Split into groups of 25 vedors. Each plot has a 5x5 facet.

plots <- 
  df %>%
  group_by(group) %>%
  group_map(function(g, ...) ggplot(g, aes(x, y)) + geom_line() + facet_wrap(~vendor, ncol = 5))

保存,以便每个图都有自己的页面.

Save so that each plot has its own page.

ggsave("plots.pdf", gridExtra::marrangeGrob(plots, nrow = 1, ncol = 1))

这篇关于在R中使用多面换行来格式化500多个图的最佳方法?[图像和包括代码]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆