您可以使用 package.json 获得类似的东西gridBase
。一旦我们处于良好视口的空间中,我们就会继续使用rose.diag
并绘制情节。hack
require(grid)
#grid.newpage()
##generate some data
x <- circular(runif(50, 0, 2*pi))
bins <- 8
rotation <- 'clock'
##tcl =0(no ticks), tcl.text=-2 to write away the ticks marks
rose.diag(x, bins=bins,zero=0, rotation='clock',
tcl=0,tcl.text=-2,col='#80FF00FF')
library(gridBase)
## I use the plot viewport
vp <- baseViewports()$plot
pushViewport(vp) ## here we go!
## radial transformation
at <- (0:bins - 0.5)/bins * 2 * pi
## ticks
grid.segments( x0 = .95*sin(at), y0 = 0.95*cos(at),
x1 = 1.05*sin(at), y1 = 1.05*cos(at),
default.units = "native")
## ticks labels
grid.text(x = 1.1*sin(at), default.units = "native",
y = 1.1*cos(at), gp=gpar(col='red'),
label = c("N", "NE", "E", "SE", "S", "SW", "W", "NW"))
对于视觉方面,我添加了一些调整,但上面的一些代码已经回答了这个问题。
## dashed lines from the center for visual aspect
grid.segments( x0 = .95*sin(at), y0 = 0.95*cos(at),
x1 = 0, 0,
gp = gpar(lty="dashed"),
default.units = "native")
## circle just to get the same color of text
grid.circle(r=1,x=0,y=0,gp=gpar(col='red',fill=NA,lwd=2), default.units = "native")
## remove the viewport
popViewport(1)