繁体   English   中英

R:如何 plot 列表中 data.frames 的数据?

[英]R: How to plot data of data.frames in a list?

我有几个data.frames的列表:

my_list <- list(d1, d2, d3,...)

每个 data.frames 看起来都一样,导致列表结构如下:

 my_list
   d1
      Temp
      Inc.Time
      Day
      Value
      lowlim
      uplim
   d2 (same)
   d3 (same)

我想 plot 我的数据,一个 plot 用于列表中的每个 data.frame,df 的名称(例如 d1)作为 Z32FA6E1B78A9D40284953E60564A2AA2A2A2 的标题。

我一次用于一个 dataframe 的代码是:

ForPlot <-  ggplot(d1, aes(Inc.Time, Value), fill=Inc.Time, width=.7)

ForPlot + 
  geom_hline(yintercept = c(0, 0.25, 0.5, 0.75, 1.0), colour= "lightgrey" )+
  geom_col( aes(fill=Inc.Time, group=Day), 
            position=position_dodge2(preserve="single"))+
  ylab("Relative Values") + xlab("Day") +
  ggtitle("d1")+
  facet_wrap(~Temperature,  scales= "free", ncol=3)+
  scale_y_continuous(breaks=c(0,0.25,0.5,0.75,1),labels=c(0,0.25,0.5,0.75,1),limits=c(0,1.05))+
  geom_text(aes(label = Day), position=position_dodge2(width= 0.9), 
            y=-0.025, size=2.3)+
  geom_errorbar(aes(ymin=pmax(0,lowlim), ymax=uplim), 
                position=position_dodge2())

关于如何在我的列表中运行它的任何想法? 预先感谢: :)

如果您通过列表的名称应用并将列表传递到lapply那么您可以 1. 提取每个列表项和 plot 的数据,2. 将列表的名称添加到 Z32FA6E1B78A9D4AAAAC28 这是一个通用示例:

library(ggplot2)

my_list <- list(a = iris, b = iris, c = iris)

p <- lapply(names(my_list), function(x, d) {
  ggplot(d[[x]], aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
    geom_point() +
    labs(title = x)
}, d = my_list)

names(p) <- names(my_list)
p$a

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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