r - ggplot2:用直线连接极坐标中的点 [英] r - ggplot2: connecting points in polar coordinates with a straight line
问题描述
我在极坐标中有一个阴谋。我用geom_path来连接点,但我希望路径是直线。这里是我迄今为止:
pre $ 示例< - data.frame(c(5,4,3),c( (示例)< -c(r,theta)
myplot< - ggplot(示例,aes(0.9,1.1,0.6))
colnames r)theta))+ geom_point(size = 3.5)+
coord_polar(theta =y,start = 3/2 * pi,direction = -1)+
scale_x_continuous(breaks = seq(0 ,max(例如$ r)),lim = c(0,max(例如$ r)))+
scale_y_continuous(break = 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()
感谢任何建议。 $ b
试试这个,但请注意,这只是一个特别的解决方法,将来可能无法使用。 $ b
示例< - data.frame(c(5,4,3),c(0.9,1.1,0.6))
colnames( (x)TRUE
coord_polar2 < - coord_polar(thet a =y,start = 3/2 * pi,direction = -1)
class(coord_polar2)<-c(polar2,class(coord_polar2))
myplot < - ggplot(例如aes(r,theta))+ geom_point(size = 3.5)+
coord_polar2 +
scale_x_continuous(breaks = seq(0,max(example $ r)),lim = c (0,max(例如$ r)))+
scale_y_continuous(break = 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 have a plot in polar coordinates. I used geom_path to connect the points, but I'd like the paths to be straight lines. 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()
这篇关于r - ggplot2:用直线连接极坐标中的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!