R geom_line不使用fun.y=mean作为参数生成线
以下是我的数据:R geom_line不使用fun.y=mean作为参数生成线,r,ggplot2,R,Ggplot2,以下是我的数据: 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 301006
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")
我真正想做的是把点连接成线。所以我认为这会起作用:
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?
我对R比较陌生。所以,请有人告诉我出了什么问题?把它翻个底朝天怎么样
#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")
#示例数据
gg把它翻一翻怎么样
#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")
#示例数据
ggI无法使用您的解决方案生成测线图。。。但我用geom_柱状图来代替,以更好地显示数据而不是点。我无法用你的解决方案生成线图。。。但我用geom_直方图来代替,以更好地可视化数据,而不是点。