我是從一個文件中獲取數據的子集,然後嘗試在ggplot2中繪製一條線。只有設法得到點(雖然我使用geom_point()+ geom_line())爲什麼我不能在子集之後劃線?
d1<-structure(list(year = structure(1:10, .Label = c("2001", "2002",
"2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010",
"2011", "2012"), class = "factor"), val1 = c(42244L, 43161L,
42444L, 43579L, 43424L, 45116L, 48003L, 48835L, 47856L, 50024L
), val2 = c(0L, 0L, 0L, 0L, 18L, 0L, 0L, 7L, 0L, 0L), val3 = c(109467L,
112956L, 110623L, 125657L, 127560L, 137180L, 156412L, 164861L,
174395L, 180413L), val4 = c(20381L, 18346L, 16636L, 18119L, 17173L,
19234L, 22113L, 22624L, 23374L, 23280L), val5 = c(7056L, 6679L,
6287L, 6261L, 7197L, 7581L, 10321L, 10535L, 10242L, 12080L),
val6 = c(12823L, 12056L, 11101L, 11428L, 12665L, 11783L,
9861L, 8250L, 7802L, 6775L), val7 = c(220L, 101L, 55L, 68L,
212L, 85L, 95L, 125L, 49L, 81L), val8 = c(694L, 2527L, 1066L,
1700L, 2976L, 1665L, 1229L, 1086L, 879L, 958L), val9 = c(12439L,
12698L, 15351L, 12771L, 13192L, 12420L, 13753L, 14943L, 14368L,
10404L), val10 = c(17819L, 18221L, 15643L, 19250L, 19326L,
20967L, 23658L, 27208L, 30526L, 34250L), val11 = c(20446L,
21236L, 19994L, 22489L, 23212L, 23792L, 25363L, 25036L, 25845L,
27074L), val12 = c(243589L, 247981L, 239200L, 261322L, 266955L,
279823L, 310808L, 323510L, 335336L, 345339L)), .Names = c("year",
"val1", "val2", "val3", "val4", "val5", "val6", "val7", "val8",
"val9", "val10", "val11", "val12"),
row.names = c(NA, 10L), class = "data.frame")
,然後我跑
d2<-subset(d1[,c(1,2)]) #(here d1 is the main (csv)file)
ggplot(d2,aes(x=year,y=val1))+geom_line()+geom_point()
# geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
爲qplot同樣的事情,使用GEOM = 「行」 時,是表示該通知,但不使用的geom =「線」,它顯示了點沒有任何音符/錯誤現在
qplot(y=val1,x=year,data=d2,geom="line")
# geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
當我手動創建一個數據幀作爲
d2<-data.frame(year=c(2001,2002,2003,2004,2005,2006,
2007,2008,2009,2010,2011,2012),
value=c(20446,21236,19994,22489,23212,23792,25363,
25036,25845,27074,28878,31117))
我可以畫線。無法弄清楚什麼是錯的。 謝謝
你需要做一個[可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。你如何對數據框進行子集劃分?你的繪圖命令究竟是什麼樣的?理想的你應該發佈一個最小的例子,我們可以複製/粘貼到R,並得到相同的錯誤 – MrFlick 2014-09-21 03:13:03
Downvoted發佈錯誤消息與不完整的代碼(因此不清楚)。 – 2014-09-21 03:14:24
完成。請確定歧義是否仍然存在。 – 2014-09-21 03:38:17