1

在 geom_col 图上标记列时,我可以使用以下代码标记它们:

geom_text(aes(x = Date, y = Cases, label = Cases), vjust = -0.5)+

Cases 的某些值为零,我不想显示这些值。

4

1 回答 1

1

您还可以在以下调用中过滤数据geom_label()

structure(list(x = c("A", "B", "C", "D", "E", "F"), n = c(3, 
5, 10, 7, 5, 0)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-6L))

ggplot2::ggplot(df, aes(x = x, y = n, label = n))+
  geom_col(stat = "identity")+
  geom_label(data = df %>% dplyr::filter(n > 0), vjust = 0.5)

在此处输入图像描述

于 2020-07-03T13:49:06.890 回答