qfd
qfd

Reputation: 788

ggplot2 - changing or dropping specific legends

I have a simple (maybe) question on ggplot2.

I would like to drop one of the variables in the legend, lets say trt1 in the example below.

How do I do that? I would still like for it to be plotted just the variable should be removed from the legend.

Thanks for all your help!

Below is a simple example:

library(ggplot2)

bp <- ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()

bp

enter image description here

Upvotes: 1

Views: 83

Answers (1)

LyzandeR
LyzandeR

Reputation: 37879

Use this. scale_fill_discrete is what you need:

library(ggplot2)

bp <- ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot() +
  scale_fill_discrete(breaks=c("ctrl","trt2"))

bp

enter image description here

Upvotes: 1

Related Questions