4
我想將一行添加到一個點的圖中,我無法弄清楚。我的y值是從0到Inf的數字,而我的x值來自有序因子。向ggplot添加一行
這裏是繪圖代碼,只顯示點:
g = ggplot() +
layer(data = ratesdf, mapping = aes(x = age, y = rates), geom = "point", stat="identity") +
layer(data = ratesdf, mapping = aes(x = age, y = rates), geom = "smooth", stat = "smooth", method = loess)
print(g)
下面是數據框:
rates age
[0,5) 0.00000000 [0,5)
[5,10) 0.00000000 [5,10)
[10,15) 0.00000000 [10,15)
[15,20) 0.02017059 [15,20)
[20,25) 0.32707402 [20,25)
[25,30) 0.54013169 [25,30)
[30,35) 0.71698958 [30,35)
[35,40) 0.81120944 [35,40)
[40,45) 0.87283637 [40,45)
[45,50) 0.91411649 [45,50)
[50,55) 0.91273334 [50,55)
[55,60) 0.95627322 [55,60)
[60,65) 0.92879819 [60,65)
[65,70) 0.98088779 [65,70)
[70,75) 0.90406674 [70,75)
[75,80) 1.00000000 [75,80)
[80,85) 1.00000000 [80,85)
[85,Inf] 1.00000000 [85,Inf]
感謝大家提前!
(哈德利,我保證,只要我得到我每年的生日禮品卡購買:)你的書)
很難說沒有一個可重複的數據幀。年齡是「因素」還是別的?對於一個區間的數學符號不是我以前在R中看到的... – Harlan 2009-11-19 00:48:42
看看這個相關的問題:http://stackoverflow.com/questions/1476185/how-to-overlay-a-line-換一個-LM-對象上-A-GGPLOT2-散點圖。 – Shane 2009-11-19 00:49:42
列時間是一個有序因子,使用cut的默認結果作爲標籤。 – forkandwait 2009-11-19 00:59:25