2014-05-23 59 views
1

這裏是我的數據:geom_line不會產生使用fun.y線=平均值作爲參數

head(BCM) 
     fips  scc pollutant emissions type year 
114288 24510 10100601 PM25-PRI  6.532 POINT 1999 
114296 24510 10200601 PM25-PRI 78.880 POINT 1999 
114300 24510 10200602 PM25-PRI  0.920 POINT 1999 
114308 24510 30100699 PM25-PRI 10.376 POINT 1999 
114325 24510 30183001 PM25-PRI 10.859 POINT 1999 
114329 24510 30201599 PM25-PRI 83.025 POINT 1999 

table(BCM$type) 
NON-ROAD NONPOINT ON-ROAD POINT 
416  142  1119  419 

table(BCM$year) 
1999 2002 2005 2008 
320 535 542 699 

我想看看污染物跨越時間的變化情況爲每種類型。這裏是我的代碼:

ggplot(aes(x = year, y = emissions), data = BCM) + 
geom_point(stat = "summary", fun.y = mean) + 
facet_wrap(~type, scale = "free") 

with geim_point

我真正想要做的是連點成線。所以,我想這會工作:

ggplot(aes(x = year, y = emissions), data = BCM) + 
geom_line(stat = "summary", fun.y = mean) + 
facet_wrap(~type, scale = "free") 

但我得到的是警告的很多行,並在其上沒有點或線圖:

geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic? 
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic? 
geom_path: Each group consist of only one observation. Do you need to adjust the group  aesthetic? 
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic? 

with geom_line

我是比較新增至R。所以請有人告訴我出了什麼問題?

回答

1

如何圍繞翻轉它

#sample data 
gg<-expand.grid(type=letters[1:4], year=2000:2004) 
df<-data.frame(
    gg, 
    emissions=runif(nrow(gg)*10) 
) 

ggplot(aes(x=year, y=emissions), data=df) + 
    stat_summary(geom="line", fun.y="mean") + 
    facet_wrap(~type, scale="free") 

stat summary line

+0

我無法生成與您的解決方案線圖......但我用geom_histogram反而比想象好點的數據。 – FinnHusky