【发布时间】:2022-01-21 21:21:03
【问题描述】:
我想在 ggplot2 poar 图中显示 theta 轴的刻度线。但是,theta 轴中的axis.ticks.y 和axis.ticks.y 都不适用于theta 轴。任何帮助将不胜感激,谢谢
library(ggplot2)
df <- data.frame(
start = c(0, 121, 241),
end = c(120, 240, 359),
group = letters[1:3]
)
# a example circular ring plot
base <- ggplot(df, aes(ymax = end, ymin = start,
xmin = 0.8, xmax = 1,
fill = group)) +
geom_rect() +
coord_polar(theta = "y") +
xlim(c(0, 1))
base
# the tick of y axis can be changed
base + theme(axis.ticks.y = element_blank(), axis.text.y = element_blank())
# set the tick of x axis not worked for the theta axis
base + theme(axis.ticks.x = element_line(color = "black", size = 2))
感谢@Vishal A.,Controlling ticks and odd text in a pie chart generated from a factor variable in ggplot2 的回答使用了panel.grid.major.y。但是,它将添加主要网格而不是像下面这样的刻度:
base + theme(panel.grid.major.y = element_line(colour = "black"))
由reprex package (v2.0.1) 于 2021 年 12 月 20 日创建
【问题讨论】: