【发布时间】:2019-05-15 09:54:01
【问题描述】:
我在使用coord_polar() 和geom_col() 时遇到问题。我的度数范围从 0 到 0, 20, 40... 340。如果我用coord_polar() 绘制它们,我有两个问题:
- 值 0 和 340 相互接触,并且与其他列的间隙不同
- “x 轴”略微偏移,因此 0 不指向“北”
查看这个最小的例子。
suppressWarnings(library(ggplot2))
df <- data.frame(x = seq(0,359,20),y = 1)
ninety = c(0,90,180,270)
p <- ggplot(df, aes(x,y)) +
geom_col(colour = "black",fill = "grey") +
geom_label(aes(label = x)) +
scale_x_continuous(breaks = ninety) +
geom_vline(xintercept = ninety, colour = "red") +
coord_polar()
p
如果我设置了x轴范围,坐标系的旋转是正确的,但是0处的列因为空间不足而消失了。
p+scale_x_continuous(breaks = c(0,90,180,270),limits = c(0,360))
#> Scale for 'x' is already present. Adding another scale for 'x', which
#> will replace the existing scale.
#> Warning: Removed 1 rows containing missing values (geom_col).
由reprex package (v0.2.1) 于 2019-05-15 创建
【问题讨论】:
标签: r ggplot2 polar-coordinates