一直在 ggplot2 中制作饼图。到目前为止我有这个代码:
library(tidyverse)
pie_tbl <- tibble(
surface = factor(c("Dry","Wet","Snow/Ice","Other"),levels=c("Dry","Wet","Snow/Ice","Other")),
percentage = c(78,14.8,6.9,0.2)
)
pie_tbl %>% ggplot(aes(x="",y=percentage,fill=surface)) +
geom_col(color='black',width=1) + coord_polar("y",start=pi/2) +
labs(title="Surface Condition during collisions") +
theme_void() +
theme(plot.title = element_text(family='serif',face='bold',size=18,hjust=0.5,vjust=-1)) +
scale_fill_manual(
values=c(
"Dry" = "#27B7CE",
"Wet" = "#FB6476",
"Snow/Ice" = "#47B972",
"Other" = "#FEB20E"
)
)
)
我明白了这个情节 饼图
vjust = -1 不会将标题移至底部。有什么想法吗?
我发现 vjust 工作的负值很大(例如 -100),但这感觉像是一个“hacky”解决方案,并且可能有更好的方法。