简体   繁体   English

r - ggplot2:用直线连接极坐标中的点

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

I have a plot in polar coordinates. 我有极坐标的情节。 I used geom_path to connect the points, but I'd like the paths to be straight lines. 我使用geom_path连接点,但我希望路径是直线。 Here's what I have so far: 这是我到目前为止所拥有的:

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

I appreciate any suggestions. 我很感激任何建议。

Try this, but note that this is just an ad-hoc workaround and may not work in future. 试试这个,但请注意,这只是一个临时的解决方法,将来可能无法使用。

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

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM