When labeling columns on a geom_col plot I can label them with this code:
geom_text(aes(x = Date, y = Cases, label = Cases), vjust = -0.5)+
some values are zero for Cases, and I would like not to show those.
When labeling columns on a geom_col plot I can label them with this code:
geom_text(aes(x = Date, y = Cases, label = Cases), vjust = -0.5)+
some values are zero for Cases, and I would like not to show those.
You could also filter the data within the call of 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)