【发布时间】:2022-06-15 19:49:20
【问题描述】:
我有以下情节:
df <- tibble(days = c(1, 1, 2, 2),
type = c("v1", "v2", "v1", "v2"),
values = c(100, 1, 2, 200))
plot <- df %>%
ggplot(aes(days, values, fill = factor(type))) +
geom_bar(stat = 'identity', position = 'dodge') +
geom_text(aes(label = values), vjust=1.6, color="white", position = position_dodge(0.9), size=3.5)
plot
如果相应的值大于特定阈值,有没有办法只在条上添加文本。在这种情况下,我想删除文本“1”和“2”(蓝色圆圈)。
【问题讨论】:
-
在调用 ggplot 之前过滤,类似于:
df %>% filter(values >5) %>% ggplot(....