【问题标题】:Creating half a polar plot (rose diagram) with circular package使用圆形包创建半个极坐标图(玫瑰图)
【发布时间】:2015-10-16 10:56:04
【问题描述】:

我正在使用 circular 库中的 rose.diag 函数绘制角度分布。输入数据是辐射。我的 MWE 代码是

    library(circular);
    dat<-read.csv(file.choose(),header=F);
    data=unlist(dat);
    rose.diag(data, bins=24)

我得到了这张图:

我有兴趣只显示从 -pi/2 到 pi/2 的部分数据,并且最大刻度的长度等于圆的半径长度,如下所示:

任何帮助将不胜感激!

编辑

正如#lawyeR 所建议的,这里是带有数据样本的代码:

    library(circular);
    data<- c(-0.188,-0.742,-0.953,-0.948,-0.953,-1.187,-0.9327200,-0.855,-  0.024,1.303,-1.041,-1.068,-1.066,1.442,1.150,0.965,0.665,0.649,0.984,-1.379,-0.584,-0.573,-0.357,-0.237,-0.287,-0.486,-0.783,-0.298,0.849,1.088,-1.003,-0.952,-0.776,-0.811,-0.880);
    rose.diag(data, bins=24);

【问题讨论】:

  • 您为什么不输入您的数据以便人们可以更好地帮助您?
  • 感谢您的回答。我已编辑帖子以添加数据示例。
  • 好。我编辑了您的问题并添加了另一个标签,希望能吸引一两个答案。

标签: r polar-coordinates


【解决方案1】:

也许您可以先使用默认绘图函数绘制没有分布的半圆。然后填写不带圆圈的分布:

library(circular)

data<- c(-0.188,-0.742,-0.953,-0.948,-0.953,-1.187,-0.9327200,-0.855,-  0.024,1.303,-1.041,-1.068,-1.066,1.442,1.150,0.965,0.665,0.649,0.984,-1.379,-0.584,-0.573,-0.357,-0.237,-0.287,-0.486,-0.783,-0.298,0.849,1.088,-1.003,-0.952,-0.776,-0.811,-0.880)

freq <- diff(colSums(outer( data %% (2*pi), (1:24)*pi/12,"<"))) / length(data)
r.max <- sqrt(max(freq))

#-----------------------------------------------------------------
# Plot the half circle:

lab.width  <- 0.15*r.max
lab.height <- 0.15*r.max

plot( c(-r.max,r.max), c(0,0),
      axes=FALSE,
      ylim=c(0,r.max+lab.height),
      xlim=c(-r.max-lab.width,r.max+lab.width),
      xlab="", ylab="", type="l")

for ( i in 0:(5*12-1) )
{
  psi <- i*pi/(5*12)
  x1 <- r.max*cos(psi)
  y1 <- r.max*sin(psi)
  x2 <- r.max*cos(psi+pi/(5*12))
  y2 <- r.max*sin(psi+pi/(5*12))

  lines( c(x1,x2), c(y1,y2), type="l")

  if (i %% 5 == 0) { lines( x1*c(1,0.95), y1*c(1,0.95), type="l" ) }
}

par(cex=2.0)

text( x = c(-r.max,0,r.max),
      y = c(0,r.max,0),
      labels = c("-pi/2","0","pi/2"),
      pos = c(2,3,4))

#------------------------------------------------------------
# Plot the distribution, but without the circle:

rose.diag(data,
          bins = 24,
          rotation = "clock",
          tcl.text = NA,
          ticks = FALSE,
          zero = pi/2,
          control.circle = circle.control( col="white" ),
          add = TRUE )

【讨论】:

  • 这是个好主意!谢谢你的帮助。我有最后一个问题:在外圈添加 -pi/2, 0, pi/2 的最佳方法是什么?
  • 我已经编辑了我的答案。您可以使用text 添加标签。
  • 非常感谢您的宝贵帮助,一切都会好的!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-29
  • 2012-06-12
  • 2014-03-07
  • 1970-01-01
  • 1970-01-01
  • 2013-09-09
相关资源
最近更新 更多