ggplot set在geom_polar中从顶部开始

时间:2015-02-03 13:47:04

标签: r ggplot2

我在设置geom_polar(theta = "y")顶部的起点时遇到问题,因为正负值具有不同的最小值和最大值。它在设置相等的y限制时有效(参见第4页)。如何正确设置起点?

示例:

df <- data.frame(x = letters[1:10], y = seq(-1.7, 1.2, length.out = 10))

plot <- ggplot(df, aes(x = x, y = y, fill = x)) + geom_bar(stat = "identity") + guides(fill = F)
p1 <- plot + coord_polar(theta = "y")
p2 <- plot + coord_polar(theta = "y", start = 0)
p3 <- plot + coord_polar(theta = "y", start = pi) #does not work
p4 <- plot + coord_polar(theta = "y", start = pi) + ylim(c(-2,2)) # does work

Plot http://www.ahschulz.de/pub/overflow/geom_polar.png

1 个答案:

答案 0 :(得分:2)

我假设您希望0位于首位,但不想指定限制。您可以像{<1}}那样重新缩放

max(y)/diff(range(y))