ggplot - 用直线连接极坐标中的点 [英] ggplot - connecting points in polar coordinates with a straight line
问题描述
我正在处理类似的问题,正如我们在此讨论过的:
是 geom_path
还是更好的选择吗?我尝试了一些使用 geom_path
的方法,但并没有真正地向我想要的方向发展。
我的问题在于这一行:
geom_segment(data = polar,aes(x = 0,y = 0,xend = Winkel2,yend = value,fill = NA),
$ b起始点x决定了箭头应该到达的方向,例如,如果设置为0,所有箭头最初将朝着我的零标记前进,并通过曲线转向它们的预期位置。为了解决这个问题,我必须设置x = Winkel2,因此每个箭头从它的个别标记开始并直接到达最终位置:
I am working on a similar issue, as already discussed here: r - ggplot2: connecting points in polar coordinates with a straight line
Unfortunately, the workaround is not working anymore.
I made up an example code to talk about my issue in particular. Here is what I tried last: I used
geom_segment
instead ofgeom_path
and I ended up with lines going in a circle. These lines always head towards zero first and then turn according to the giving position, instead of taking the straight way.require(grid) require(ggplot2) set.seed(40); Location<-data.frame(Winkel=round(runif(1000,0,24),0)) Location$BAD <- Location$Winkel %in% c(seq(7,18)) Abschnitte<-c(0:24) polar<-data.frame(Winkel2=c(1.5, 2.34, 1.2, 3.45, 1.67, 2.61, 1.11, 13.2), value=c(0.1, 0.03, 0.02, 0.015, 0.01, 0.04, 0.09, 0.06), .Names=c("Winkel2", "value")) ggplot(Location, aes(x = Winkel, fill = BAD, y=(..count..)/sum(..count..))) + geom_histogram(breaks = seq(0,24), colour = "black") + coord_polar(start = 0) + theme_minimal() + scale_fill_brewer(type="seq",palette=3) + ylab("Percentual allocation time") + ggtitle("") + scale_x_continuous("", limits = c(0, 24), breaks = Abschnitte, labels = Abschnitte) + scale_y_continuous(labels = scales::percent)+ geom_segment(data=polar, aes(x=0, y=0, xend=Winkel2, yend=value, fill=NA), arrow=arrow(angle=30,type="closed",length=unit(0.3,"cm")))
Is
geom_path
still the better option? I tried some things withgeom_path
, but didn't really get towards where I wanted.解决方案I solved the issue myself and wanted to share my findings:
My problem was in this line:
geom_segment(data=polar, aes(x=0, y=0, xend=Winkel2, yend=value, fill=NA),
The starting point x determines the direction, in which the arrow should head to in the first place. E.g. if set to 0, all arrows will initially head towards my zero mark and turn towards their intended postion by making curves. To solve the issue, I had to set x=Winkel2, thus each arrow starts at its individual mark and goes straight to the final position:
这篇关于ggplot - 用直线连接极坐标中的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!