0

Is there a way to customize the labels in a legend when utilizing ggboxplot? I have a barplot with a legend in which the labels are taken from the data frame columns. I would like to change these labels without having to change the label of the column. Something akin toscale_fill_discrete(labels=c(......) in ggplot.

David
  • 67
  • 2
  • 9

2 Answers2

0

I tweaked @Nicolás Velásquez answer a bit. You can also use

scale_fill_discrete(labels = c("First", "Second"))

This also works for gghistogram

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 10 '23 at 19:27
-1

Certainly. Ggplot2's scale_x_discrete() will do the trick.

ggBoxplot(as.data.frame(DFW2), y = 'shares', x = 'Polaridad') +
          scale_x_discrete(labels = c("First", "Second"))

ggboxplot() is but a wrapper around ggplot2's ggplot() and geom_box() functions, so all instructions for layers after ggplot() will work.

Nicolás Velasquez
  • 5,623
  • 11
  • 22