1

I'm new to using ggplot. I'm looking to just specify the colors I want for the group (i.e. High = red4; Low = gray45). Group is defined by "high" or "low" values.

ggplot(my_data, aes(x=continuous_variable, fill=Group)) + geom_histogram() + 
  xlab("continuous_variable")+ 
  ylab("Frequency") + 
  ggtitle("My Variable")
vestland
  • 55,229
  • 37
  • 187
  • 305
Neuro H
  • 81
  • 1
  • 5

1 Answers1

2

Axeman pointed you already into the right direction: just add scale_fill_manual to your code.

Reproducible example:

library(ggplot2)

# sample data
set.seed(1234)
continuous_variable <- rnorm(100)
Group <- factor(rep(c("high", "low"), 50))
my_data <- data.frame(continuous_variable, Group)

# just add another line to your initial code
ggplot(my_data, aes(x = continuous_variable, fill = Group)) + geom_histogram() + 
  xlab("continuous_variable") + 
  ylab("Frequency") + 
  ggtitle("My Variable") + 
  scale_fill_manual(values = c("high" = "red4", "low" = "grey45"))
#> stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.

Thomas K
  • 3,242
  • 15
  • 29
  • AWESOME. I just added: scale_fill_manual(values = c("red4", "grey45")), and it didn't work Didn't know I needed to specify the "high" and "low". Thank you!!! – Neuro H Sep 29 '15 at 22:28