ggplot 在 geom_polar 中设置从顶部开始
ggplot set start in top in geom_polar
当正值和负值具有不同的最小值和最大值时,我无法将 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
(来源:ahschulz.de)
我假设您希望 0
位于顶部,但不想指定限制。您可以像这样 max(y)/diff(range(y))
重新缩放
plot + coord_polar(theta = "y", start = 2*pi*max(df$y)/diff(range(df$y)))
当正值和负值具有不同的最小值和最大值时,我无法将 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
(来源:ahschulz.de)
我假设您希望 0
位于顶部,但不想指定限制。您可以像这样 max(y)/diff(range(y))
重新缩放
plot + coord_polar(theta = "y", start = 2*pi*max(df$y)/diff(range(df$y)))