使用R''shape'包(或其他包装?)绘制彩色(热)圆形段?

时间:2011-10-30 19:49:34

标签: r

我需要创建一个方位角/距离颜色编码的图,就像使用'shape'包的跟随代码一样。


library(shape)
emptyplot(xlim=c(-5,10), main="color segment test case")

filledcircle(r1=1, r2=2, from=0, to=pi/6, col=intpalette(c("blue", "yellow","red"),    numcol = 100),
val=(cbind(c(0,1),c(.0,.0))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=1, r2=2, from=pi/6, to=2*pi/6, col=intpalette(c("blue", "yellow","red"),   numcol = 100), 
val=(cbind(c(0,1),c(.1,.1))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=1, r2=2, from=2*pi/6, to=3*pi/6, col=intpalette(c("blue", "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.2,.2))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=1, r2=2, from=3*pi/6, to=4*pi/6, col=intpalette(c("blue", "yellow","red"), numcol = 100), 
val=(cbind(c(0,1),c(.3,.3))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=1, r2=2, from=4*pi/6, to=5*pi/6, col=intpalette(c("blue", "yellow","red"), numcol = 100), 
val=(cbind(c(0,1),c(.4,.4))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=1, r2=2, from=5*pi/6, to=6*pi/6, col=intpalette(c("blue",   "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.5,.5))), zlim=c(0,1),  mid=c(0.0,0.0))

filledcircle(r1=2, r2=3, from=0, to=pi/6,col=intpalette(c("blue", "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.6,.6))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=2, r2=3, from=pi/6, to=2*pi/6,col=intpalette(c("blue", "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.7,.7))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=2, r2=3, from=2*pi/6, to=3*pi/6,col=intpalette(c("blue", "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.8,.8))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=2, r2=3, from=3*pi/6, to=4*pi/6,col=intpalette(c("blue", "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.9,.9))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=2, r2=3, from=4*pi/6, to=5*pi/6,col=intpalette(c("blue", "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.99,.99))), zlim=c(0,1), mid=c(0.0,0.0))
filledcircle(r1=2, r2=3, from=5*pi/6, to=6*pi/6,col=intpalette(c("blue", "yellow","red"), numcol = 100),
val=(cbind(c(0,1),c(.8,.8))), zlim=c(0,1), mid=c(0.0,0.0))

segments(0,0,3,0)
segments(0,0,2.6,1.5)
segments(0,0,1.5,2.6)
segments(0,0,0,3)
segments(0,0,-1.5,2.6)
segments(0,0,-2.6,1.5)
segments(0,0,-3,0)

plotcircle(r=1, from=0, to=pi, lwd=1)
plotcircle(r=2, from=0, to=pi, lwd=1)
plotcircle(r=3, from=0, to=pi, lwd=1)

这个图的真实世界的例子需要十个或更多的半径,并且可能需要另一半的图,甚至可能需要更精细的方位角范围。这将需要数十个甚至更多的代码行。

这个情节类似于风玫瑰情节,各种R包(climatol for one)做了类似的事情,但没有完全像这个情节。我看过CircStats,圆形,NeatMap,ggplot2和climatol,似乎没有任何东西符合要求。

有没有人知道另一个R包可以创建这种情节,只需要输入数据帧或数字矩阵和调色板定义?

1 个答案:

答案 0 :(得分:5)

使用ggplot2肯定可以实现这种情节。从coord_polar的帮助页面引用:

library(ggplot2)
data(movies)
movies$rrating <- cut_interval(movies$rating, length = 1) 
movies$budgetq <- cut_number(movies$budget, 4)
doh <- ggplot(movies, aes(x = rrating, fill = budgetq))
doh + geom_bar(width = 0.9, position = "fill") + coord_polar(theta = "y")

enter image description here