简体   繁体   English

ggplot2:极坐标图中缺少坐标值

[英]ggplot2: missing coordinate value in polar plot

I would like to make a polar plot of a bunch of points. 我想做一堆极点图。 So here is my code using ggplot2 : 所以这是我使用ggplot2代码:

x <- runif(min = -pi, max = pi, n = 100)
y <- runif(n = 100)
df1 <- data.frame(x = x, y = y)
library(ggplot2)
ggplot(df1, aes(y = y, x = x)) +  
  geom_point() + 
  ylim(0,1)  + 
  theme_light() +
  theme(legend.position="none",  panel.border=element_blank(), 
        axis.title = element_blank(), axis.text.y = element_blank()) + 
  scale_x_continuous(labels = paste(seq(-180,180,30)),
                     breaks = seq(-pi,pi, length=13)) + 
  coord_polar()

I get the following plot: 我得到以下情节:

在此处输入图片说明

However, as we can see, the axis for 180 is missing. 但是,正如我们所看到的,缺少180的轴。 How do I get this? 我怎么得到这个? (I do not want to have the scale for y show up at the same time, or if it does, then to be able to control what gets shown there.) (我不想同时显示y的比例尺,或者如果显示的话,则希望能够控制在那里显示的比例。)

Any suggestions? 有什么建议么?

You can add in a vertical line at pi but make it transparent. 您可以在pi处添加垂直线,但使其透明。 If you use xintercept=c(-pi,pi) you will get -180/180 as a label. 如果使用xintercept=c(-pi,pi) ,则将获得-180/180作为标签。

ggplot(df1, aes(y = y, x = x)) +  
  geom_point() + 
  ylim(0,1)  + 
  theme_light() +
  geom_vline(aes(xintercept=pi), col='transparent') + 
  theme(legend.position="none",  panel.border=element_blank(), 
        axis.title = element_blank(), axis.text.y = element_blank()) + 
  scale_x_continuous(labels = paste(seq(-180,180,30)),
                     breaks = seq(-pi,pi, length=13)) + 
  coord_polar()

在此处输入图片说明

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

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