【问题标题】:r - ggplot2: connecting points in polar coordinates with a straight liner - ggplot2:用直线连接极坐标中的点
【发布时间】:2014-07-05 20:05:59
【问题描述】:

我有一个极坐标图。我使用 geom_path 连接点,但我希望路径是直线。这是我到目前为止所拥有的:

example <- data.frame(c(5,4,3),c(0.9,1.1,0.6))

colnames(example) <- c("r", "theta")

myplot <- ggplot(example, aes(r, theta)) + geom_point(size=3.5) +
  coord_polar(theta="y", start = 3/2*pi, direction=-1) + 
  scale_x_continuous(breaks=seq(0,max(example$r)), lim=c(0, max(example$r))) + 
  scale_y_continuous(breaks=round(seq(0, 2*pi, by=pi/4),2), expand=c(0,0), lim=c(0,2*pi)) +
  geom_text(aes(label=rownames(example)), size=4.4, hjust=0.5, vjust=-1) + 
  geom_path()

感谢任何建议。

【问题讨论】:

  • This 可能会给你一些想法。经过一些初步尝试(“(3)使用 ggplot2 创建径向图”)与您的问题类似(“主要问题 [...] 需要连接绘制点的直线”),它们最终以“ (5) 使用函数 CreateRadialPlot" 创建一个径向图。
  • This Q&A 显示与曲线相同的问题。提到了fmsb 包中的radarchart
  • 感谢 Henrik 的提示。我会查看您推荐的页面。

标签: r ggplot2 lines polar-coordinates


【解决方案1】:

试试这个,但请注意,这只是一种临时解决方法,将来可能不起作用。

example <- data.frame(c(5,4,3),c(0.9,1.1,0.6))

colnames(example) <- c("r", "theta")
is.linear.polar2 <- function(x) TRUE
coord_polar2 <-   coord_polar(theta="y", start = 3/2*pi, direction=-1) 
class(coord_polar2) <- c("polar2", class(coord_polar2))

myplot <- ggplot(example, aes(r, theta)) + geom_point(size=3.5) +
  coord_polar2+
  scale_x_continuous(breaks=seq(0,max(example$r)), lim=c(0, max(example$r))) + 
  scale_y_continuous(breaks=round(seq(0, 2*pi, by=pi/4),2), expand=c(0,0), lim=c(0,2*pi)) +
  geom_text(aes(label=rownames(example)), size=4.4, hjust=0.5, vjust=-1) + 
  geom_path()

【讨论】:

  • 谢谢 kohske!我对使用 ggplot2 还很陌生,所以我希望你能解释一下 is.linear.polar2 &lt;- function(x) TRUEclass(coord_polar2) &lt;- c("polar2", class(coord_polar2)) 各自做了什么来实现直线
  • @Maria 它们是 ggplot2 的深层内部,所以这里很难解释。
  • 没问题!谢谢 kohske!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-04
  • 1970-01-01
  • 2012-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多