r-ggplot2 : connecting points in polar coordinates with a straight line

标签 r ggplot2 lines polar-coordinates

我有一个极坐标图。我使用 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()

我很感激任何建议。

最佳答案

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

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()

enter image description here

关于r-ggplot2 : connecting points in polar coordinates with a straight line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24590154/

相关文章:

r - 使用 ggplot 以置信区间绘制时间序列

mysql - 如何使用 RODBC 将数据帧添加到 mysql 表

r - Shiny + SQLite - 为什么Shiny 非常慢?

R - 如何在 PDF 的一页上打印三个以上的表格

r - ggplot 和 rshiny plot 未刷新

swift - 如何在不丢失顺序的情况下删除 Swift 中字符串的重复行?

从命令行渲染 R 演示文稿

计算文件中的行数,不包括 C 中的空行

css - 我可以仅使用 <br> 将带编号的源代码行应用到 css 中吗?

r - 如何删除ggplot2中的图例标题?