Add independent labels to ggplot (weighted) violin plot

I'm attempting to add a set of extra explanatory labels to each factor in a ggplot weighted violin plot. In the dummy example below I would like the field 'extra' in the dataframe'LBLS' to plot the label at y-value 2, which is just below each respective violin. This attempt did not work as there is something I'm not understanding about the way ggplot works (yet).

require(ggplot2)
LBLS <- data.frame(c("Species A", "Species B","Species C"))
names(LBLS) <- "Extra"

ggplot(data = iris, aes_string(x = names(iris)[5], y = names(iris)[2], fill = names(iris)[5] ), weight = names(iris)[4]) +             # data and weight
  geom_violin(show.legend = FALSE) +
  ggtitle("Weighted violin plots") +
  geom_label(x = names(iris)[5], y = 2,  label = LBLS$Extra)


Read more here: https://stackoverflow.com/questions/68478269/add-independent-labels-to-ggplot-weighted-violin-plot

Content Attribution

This content was originally published by Markm0705 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: