我想在coord_polar帶有geom_point. 這是一個可重現的示例:
library(ggplot2)
ggplot(mtcars, aes(x = hp, y = mpg, color = factor(am)))
geom_point()
coord_polar()
labs(color = 'am')

使用reprex v2.0.2創建于 2022-10-31
在這里,您可以看到 y 軸標簽在側面,但我希望它們位于極坐標圖中。我知道你可以這樣使用annotate:
library(ggplot2)
ggplot(mtcars, aes(x = hp, y = mpg, color = factor(am)))
geom_point()
coord_polar()
labs(color = 'am')
annotate('text', x = 0, y = c(15, 20, 25, 30), label = c('15', '20', '25', '30'))

使用reprex v2.0.2創建于 2022-10-31
但這不是很自動。所以我想知道是否有一種自動方法可以coord_polar在上面的圖表中添加 y 軸標簽?
uj5u.com熱心網友回復:
為了讓您開始:您可以提取休息時間并應用它們以使其至少“半自動”:
library(ggplot2)
p1 <- ggplot(mtcars, aes(x = hp, y = mpg, color = factor(am)))
brk <- ggplot_build(p1)$layout$panel_params[[1]]$y$breaks
brk <- brk[-c(1, length(brk))]
ggplot(mtcars, aes(x = hp, y = mpg, color = factor(am)))
geom_point()
coord_polar()
labs(color = 'am')
theme(axis.ticks.y=element_blank(),
axis.text.y=element_blank())
annotate('text', x = 0, y = brk, label = as.character(brk))

使用reprex v2.0.2創建于 2022-10-31
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/527542.html
標籤:rggplot2
上一篇:ggplot2:通過函式修改除第一個軸標簽之外的所有標簽
下一篇:基于相同的列值Sql創建列的排列
