ggplot2, казалось бы, помещает разные точки в одну и ту же точку x?

У меня проблемы с графиком ggplot2. Я пытаюсь отобразить набор точек, где ось X является годом, а ось Y является плавающей точкой. Есть два аспекта, "тип" и "группа", которые имеют 4 и 2 значения соответственно. Как ни странно, значения года, которые различны, как представляется, помещаются в одну и ту же позицию года на графиках. Я предполагаю, что делаю что-то не так, но не уверен что.

участок

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 ответ

Решение

Не нужно указывать w для вашей оси, так как ее qplot уже знает это из параметра data. Смотрите ниже, это дает мне результат, который я ожидаю.

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

Другие вопросы по тегам