我需要创建一个方位角/距离颜色编码的图,就像使用'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)
Run Code Online (Sandbox Code Playgroud)
该图的真实世界示例将需要大约十个或更多半径,并且可能需要该图的另一半,甚至可能需要更精细的方位角范围.这将需要数十个甚至更多的代码行.
这个图类似于风玫瑰图,各种R包(climatol for one)做了类似的事情,但没有完全像这个情节.我看过CircStats,圆形,NeatMap,ggplot2和climatol,似乎没有任何东西符合要求.
有没有人知道另一个R包可以通过提供数据帧或数字矩阵和调色板定义来创建这种情节?
这种类型的情节当然可以使用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")
Run Code Online (Sandbox Code Playgroud)
