圆形等高线图用R.

时间:2014-06-11 19:35:58

标签: r graphics

我试图用点密度(kde2d)创建一个圆形图作为轮廓线。 我尝试使用VecStatGraphs2D并运行DrawPoints(),但我的轮廓线保持在绘图的中心。

有没有办法让轮廓密度适应圆形图?

谢谢。

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.52653210, -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)

1 个答案:

答案 0 :(得分: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.52653210, -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)