【发布时间】:2014-03-01 03:29:21
【问题描述】:
我有一个名为“proc.r1”的 21 个不同数据帧的列表。
我正在尝试制作 21 个图表,每个图表都使用列表中每个数据框的数据。
我在下面所做的仅适用于列表中的第一个数据框。我为“plotdf1”编写的 ggplot 是我需要从每个数据帧生成的图表。所以我需要 21 个外观相同的“plotdf1”,除了每个都将显示来自不同数据帧的数据。
#making the first data frame in the "proc.r1" list as a separate data frame
df1 <- as.data.frame(proc.r1 [[1]])
#making all the NA values displayed as 0
df1[is.na(df1)] <- 0
#rounding off the "norm.n" column, which I'll use as a label in the plot, to just 1 decimal point
df1 [,42] <- round(df1[,42],1)
plotdf1 <- ggplot(df1)+geom_rect(aes(xmin=0,xmax=5,ymin=0,ymax=5))+facet_grid(row~col)+geom_text(aes(x=2.5,y=2.5,label=norm.n,colour="white"))
有没有办法可以循环这个,以便生成 21 个图表? 我真的不想在“df21”之前制作“df1”、“df2”、“df3”等,然后将所有名称复制到这几行函数中,并且必须执行“plotdf1”、“plotdf2”、“plotdf3” "等等等等。
如果这个问题令人困惑,请告诉我。
提前致谢!
【问题讨论】: