2014-06-11 75 views
1

我正在嘗試創建一個具有點(kde2d)密度作爲輪廓線的圓形圖。 我嘗試了VecStatGraphs2D和函數DrawPoints(),但是我的輪廓線停留在圖的中心。圓形等值線圖與R

有沒有辦法讓輪廓密度適應圓形圖?

謝謝。

xpro=c(1.16308024,0.99051063,0.78678278,0.55445502,0.30484876,0.04177979, 
-0.22684955,-0.50092483,-0.75089505,-0.97575418, -1.17035110,-1.32667884, 
-1.43698391, -1.50215920, -1.52003412, -1.49875433, -1.43552128, -1.32658839, 
-1.17831637, -0.98867817, -0.76562410, -0., -0.28165935, 
-0.02405296,0.22144031, 0.46379417, 0.71271683 , 0.92422959 , 1.11401445, 
1.27145801,1.39105263, 1.46019223, 1.48935942 , 1.47639548, 1.41523618, 
1.31092337) 

ypro=c(0.93242529, 1.12330395, 1.27965210 , 1.40265139 , 1.48274698, 
1.51774928,1.50375779 , 1.43949439, 1.32668863 ,1.17372907, 0.98148295 , 
0.75822803,0.51481021, 0.25961270 , 0.01227645, -0.24549260, -0.48850422 
,-0.72501604,-0.94185727, -1.13123183, -1.28919058, -1.40049946, -1.46641736, 
-1.49052896,-1.47395022, -1.41384470, -1.30528519, -1.16156716, -0.98008831, 
-0.76666689,-0.52320437, -0.27114156, -0.01705283, 0.22947899, 0.48975048, 
0.73279523) 



library(RColorBrewer) 
k <- 11 
my.cols <- rev(brewer.pal(k, "RdYlBu")) 

#basic plot: 
plot(xpro,ypro,col="#0000004C",ylim=c(min(ypro)-0.02,max(ypro)+0.02)) 
contour(kde2d(xpro,ypro),add=T,lwd=1.5,col=my.cols,nlevels=2) 

#circular : 
DrawPoints(xpro,ypro) 
contour(kde2d(xpro,ypro),add=T,lwd=1.5,col=my.cols,nlevels=2) 
+0

能否請您做一個[重複的例子(http://stackoverflow.com/問題/ 5963269/how-to-make-a-great-r-reproducible-example)包括一些樣本數據和你已經試過的代碼? – MrFlick

+0

對不起,這裏有一些數據 – user3192383

回答

0

我不確定如果這是你的意思,但在這裏是一個圓形密度圖:

library(circular) 

xpro=c(1.16308024,0.99051063,0.78678278,0.55445502,0.30484876,0.04177979, 
    -0.22684955,-0.50092483,-0.75089505,-0.97575418, -1.17035110,-1.32667884, 
    -1.43698391, -1.50215920, -1.52003412, -1.49875433, -1.43552128, -1.32658839, 
    -1.17831637, -0.98867817, -0.76562410, -0., -0.28165935, 
    -0.02405296,0.22144031, 0.46379417, 0.71271683 , 0.92422959 , 1.11401445, 
    1.27145801,1.39105263, 1.46019223, 1.48935942 , 1.47639548, 1.41523618, 
    1.31092337) 

#make circular 
xproC<-circular(xpro,modulo ="2pi", units="radians", rotation="counter") 

rose.diag(xproC, bins=12, col="NA", 
     axes = FALSE,ticks = FALSE, shrink=1.5,border='NA') 

lines(density.circular(ypro, bw=12), lwd=2.5, lty=1, 
    col = 'green',shrink=.6)