【发布时间】:2021-09-27 20:58:40
【问题描述】:
带有一些图的列表列:
mydiamonds <- diamonds %>%
group_by(cut, color) %>%
nest %>%
mutate(plots = map(data, ~ ggplot(.x, aes(x = x, y = price)) + geom_point()))
mydiamonds
# A tibble: 35 × 4
# Groups: cut, color [35]
cut color data plots
<ord> <ord> <list> <list>
1 Ideal E <tibble [3,903 × 8]> <gg>
2 Premium E <tibble [2,337 × 8]> <gg>
3 Good E <tibble [933 × 8]> <gg>
4 Premium I <tibble [1,428 × 8]> <gg>
5 Good J <tibble [307 × 8]> <gg>
6 Very Good J <tibble [678 × 8]> <gg>
7 Very Good I <tibble [1,204 × 8]> <gg>
8 Very Good H <tibble [1,824 × 8]> <gg>
9 Fair E <tibble [224 × 8]> <gg>
10 Ideal J <tibble [896 × 8]> <gg>
# … with 25 more rows
我想使用facet_wrap() 打印出每个图,以便它们一起出现在一个图表中。但我什至还不能一张一张地打印出来。试过了:
mydiamonds %>% map(plots, ~print(.x))
Error in as_mapper(.f, ...) : object 'plots' not found
我希望从 sn-p 中清楚我想要做什么 - 只需打印出每个图(这是在 Rmd 代码块内,所以会很好地打印出来)
奖励 - 假设我知道如何将它们打印出来,是否可以使用 facet_wrap() 将它们放到单个图表上,其中标题为 paste0(cut, "|", color)?
【问题讨论】: