当绘制百分比且列处于 100% 时,值标签将从图表中删除。
Two possible solutions to this are:
1. scale_y_continuous(limits = c(0, 1.1)
2. scale_y_continuous(expand = c(0, 0, 0.2, 0)
But both solutions expand the axis. I would prefer to just add a padding/margin so that I don't get a long line above 100%. Is this possible?
工作示例
library(ggplot2)
library(magrittr)
data.frame("value" = c(0, 0.5, 1),
"v1" = letters[1:3]) %>%
ggplot(aes(x = v1,
y = value,
label = value)) +
geom_bar(stat = "identity") +
geom_text(stat = "identity",
vjust = -1) +
scale_y_continuous(breaks = seq(0, 1, 0.2),
limits = c(0, 1),
labels = scales::percent,
expand = c(0, 0, 0.2, 0)) +
theme_classic()