5

R の 'circular' パッケージと rose.diag 関数を使用して、合計 8 つのビンの N、NE、E などの基本的な側面を持つ、位置データの側面のバラ図を作成しました。ただし、ビンはアスペクトにまたがりません。つまり、最初のビンは 0 から 45 まで、2 番目のビンは 45 から 90 までというように、奇妙な方法でアスペクト データをプールしています。ビンをシフトして、0、45、90 などがエッジではなくビンの中心になるようにする方法はありますか?

rose.diag(Degrees$Degrees, bins=8,zero=pi/2, units = 'degrees', rotation='clock')
4

3 に答える 3

5

では簡単にはできないというベンの意見は正しいと思いrose.diagますggplot2

library(ggplot2)
Degrees <- runif(100, 0, 360)
rose <- ggplot(mapping = aes(x = Degrees)) +
  stat_bin(breaks = (0:8 - 0.5)/8 * 360) +
  scale_x_continuous(
    breaks = 0:7/8*360, 
    labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW")
    ) +
  coord_polar(start=-pi/8)
rose

ここに画像の説明を入力rose.diagのすべての機能が ggplot2 で簡単に同等で あるとは限らないため、これは理想的ではない可能性があります。

于 2013-01-08T06:48:29.790 に答える
1

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)
于 2013-01-08T08:44:45.213 に答える
0

元のデータを回転させてみませんか? cdat の下の Nb は度数 (ゼロ = pi / 2) であり、ゼロは 2*pi です。

rose.diag(cdat - 10、ビン = 20、col="darkgrey"、prop=1.3、軸 = FALSE、追加 = TRUE、ゼロ = pi/2-pi/20)

私が取り組んでいるものをコピー/貼り付けます:

library(circular)

raw <-read.csv("C:\\Users\\Andy\\Desktop\\business\\research\\Oxford\\MichelDish\\r.csv", header=T)
raw <-na.omit(raw)


cdat <- circular(raw [, c ("kandUnknown")],type="angles",units="degrees", rotation="clock", zero=pi/2)


plot(cdat, cex=1.1, bin=720, stack=TRUE, sep=0.035, shrink=1.8, tcl.text=.2)


ticks.circular(circular(seq(0,2*pi,pi/8)), zero=pi/2, rotation='clock', tcl=0.075)



rose.diag(cdat - 10, bins = 20, col="darkgrey", prop=1.3, axes=FALSE, add=TRUE, zero = pi/2 - pi/20)

lines(density.circular(cdat, bw=40), lwd=2, lty=1)

ここに画像の説明を入力

nb 以下のコードは、古い図 (左上) を提供します。

rose.diag(cdat, bins = 20, col="darkgrey", prop=1.3, axes=FALSE, add=TRUE)

ps 好奇心旺盛な人のために、たとえばhttp://www.sciencedirect.com/science/article/pii/S0950329315001068などの統計を使用しています。

于 2015-09-15T07:58:12.483 に答える