2015-10-11 24 views
0

我需要从具有17个数字列的data.frame中为科学纸张创建16个bar plots in one figure(构面或拆分屏幕),并使用参数split来分隔酒吧由月。我有16个蒸发方法的大数据框,每月平均值。我尝试通过分面和分屏来做到这一点,但我无法做到。我已经附加了数据图像。我希望找到解决方案。最好的问候如何使用多列和参数“拆分”创建一个条形图

+4

欢迎来到SO!请显示您使用的代码(您的数据样本),又名[可重现的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example ) – RHA

回答

0

看看如何将数据从宽到长的格式重新整形。那么你可以使用ggplot:

# create sample data 
df <- cbind(Month = 1:12, as.data.frame(replicate(16, runif(12)))) 

# reshape it from wide to long format 
df <- reshape(df, idvar = 1, varying = list(-1), times = names(df)[-1], direction = "long", sep = "", timevar = "key", v.names = "value") 

# Facetted bar plot 
library(ggplot2) 
ggplot(df, aes(x = Month, y = value)) + 
    geom_bar(stat = "identity") + 
    facet_wrap(~key) 
相关问题