How to include geom_label for a column ggplot?
Solution 1:
You could achieve your desired result like so:
- As for the bars set
position="fill"
ingeom_label
too. - To only add the
val
ifcount=TRUE
use anifelse
which assigns anNA
toFALSE
. - To silence the warning about removed missing use
na.rm=TRUE
.
library(ggplot2)
ggplot(test, aes(x = pct, y = `Marketing Variables`, fill = count)) +
geom_col(position = "fill") +
geom_label(aes(label = ifelse(count, val, NA_character_)), position = "fill", na.rm = TRUE, show.legend = FALSE) +
theme_minimal() +
facet_wrap(~LICENCE_STATUS)