ggplot2似乎在同一个x位置放置了不同的点?

时间:2015-05-21 17:18:49

标签: r plot ggplot2 facets

我遇到了ggplot2情节的问题。我正在尝试显示一组点,其中x轴是年,y轴是浮点。有两个方面,'类型'和'组',分别有4和2个值。奇怪的是,年份的不同价值似乎被放置在地块的同一年位置。我认为我做错了什么,但不确定是什么。

Plot

library(ggplot2)

csv <- '"","year","type","meanPM2.5","group"
"1","1999","NON-ROAD",0.650193156943192,"Baltimore"
"2","1999","NONPOINT",53.8128535945545,"Baltimore"
"3","1999","ON-ROAD",0.384811951879435,"Baltimore"
"4","1999","POINT",23.7744225574713,"Baltimore"
"5","2002","NON-ROAD",0.556466983374061,"Baltimore"
"6","2002","NONPOINT",33.4348242946658,"Baltimore"
"7","2002","ON-ROAD",0.173168130596644,"Baltimore"
"8","2002","POINT",14.131129233003,"Baltimore"
"9","2005","NON-ROAD",0.512356196792363,"Baltimore"
"10","2005","NONPOINT",31.8169245427152,"Baltimore"
"11","2005","ON-ROAD",0.148555691013436,"Baltimore"
"12","2005","POINT",13.6351701910803,"Baltimore"
"13","2008","NON-ROAD",0.295555123686582,"Baltimore"
"14","2008","NONPOINT",20.8642755980118,"Baltimore"
"15","2008","ON-ROAD",0.117856744706526,"Baltimore"
"16","2008","POINT",2.24419944428104,"Baltimore"
"17","1999","NON-ROAD",5.81044444444444,"Total"
"18","1999","NONPOINT",84.305,"Total"
"19","1999","ON-ROAD",1.80635416666667,"Total"
"20","1999","POINT",22.8303846153846,"Total"
"21","2002","NON-ROAD",2.16979209254948,"Total"
"22","2002","NONPOINT",41.9305555555556,"Total"
"23","2002","ON-ROAD",0.418407542677101,"Total"
"24","2002","POINT",8.49641791044776,"Total"
"25","2005","NON-ROAD",2.2426458532036,"Total"
"26","2005","NONPOINT",41.9305555555556,"Total"
"27","2005","ON-ROAD",0.402562900882384,"Total"
"28","2005","POINT",16.9364788732394,"Total"
"29","2008","NON-ROAD",0.536765014018269,"Total"
"30","2008","NONPOINT",30.5157179549356,"Total"
"31","2008","ON-ROAD",0.313033536852635,"Total"
"32","2008","POINT",1.28722083560821,"Total"'

w <- read.csv(text = csv)
qplot(w$year, w$meanPM2.5, data=w, facets = type~group)

1 个答案:

答案 0 :(得分:2)

无需为轴指定w,因为qplot已经从data参数中知道了这一点。见下文,它给出了我期望的结果。

qplot(year, meanPM2.5, data=w, facets = type~group