I have a dataset that is very small. It is this
activity <- data.frame(
stringsAsFactors = FALSE,
Gender = c("male", "female", "male", "female","male", "female", "male", "female"),
Season = c("Spring","Spring","Summer","Summer","Fall","Fall","Winter","Winter"),
n = c(450,280,890,720,300,250,300,250),
check.names = FALSE
)
dput(activity)
Gender | Season | n |
---|---|---|
Male | Spring | 450 |
Female | Spring | 280 |
Male | Summer | 890 |
Female | Summer | 720 |
Male | Fall | 300 |
Female | Fall | 250 |
Male | Winter | 300 |
Female | Winter | 250 |
I want to create a histogram to distinguish between male and female activity during season
ggplot(data = activity, mapping = aes( x = Season,
y = n)) + geom_bar( mapping = aes(fill = Gender),
position = "dodge",
stat = "identity") + ggtitle (Activity by Season and Gender)
This code above works well, but the colors are really ugly. I want blue for men and red for woman.
I gave that code below to change it
ggplot(data = activity, mapping = aes( x = Season,
y = n)) + geom_bar( mapping = aes(fill = Gender), palette= c("blue","red"),
position = "dodge",
stat = "identity")
The code doesn't work. What I am doing wrong???
I had this from a programming book and there it works like this, but this code doesn't change the colors