1

I am trying to change my bar graphs to these colours: "#dda832" "#165e70" "#d5927c" "#4f9694" but for some reason it doesn't work when I use scale_fill_manual(values=c("#dda832" "#165e70" "#d5927c" "#4f9694")). I think it is because I am using "mean" instead of "identity". Does anyone know how to change this? :)

My data is as follows:

structure(list(`video number` = 1:40, category = c("neutral", 
"neutral", "neutral", "neutral", "neutral", "neutral", "neutral", 
"neutral", "neutral", "neutral", "pleasant", "pleasant", "pleasant", 
"pleasant", "pleasant", "pleasant", "pleasant", "pleasant", "pleasant", 
"pleasant", "unpleasant", "unpleasant", "unpleasant", "unpleasant", 
"unpleasant", "unpleasant", "unpleasant", "unpleasant", "unpleasant", 
"unpleasant", "painful", "painful", "painful", "painful", "painful", 
"painful", "painful", "painful", "painful", "painful"), frequency = c(55, 
56, 90, 104, 47, 38, 48, 52, 43, 38, 162, 139, 137, 131, 143, 
177, 151, 117, 164, 82, 116, 75, 105, 67, 75, 61, 133, 109, 123, 
150, 196, 191, 182, 141, 151, 148, 181, 77, 134, 128), intensity = c(2.8, 
2.7, 3.2, 3.2, 3.5, 2.6, 3.2, 2.9, 3.4, 2.8, 3.6, 3.6, 3.7, 3.5, 
3.7, 3.9, 3.6, 3.6, 3.6, 3.4, 3.8, 3.2, 3.7, 3.7, 3.3, 3.6, 4.4, 
3.7, 3.8, 4.2, 5, 4.8, 4.4, 4, 4.1, 3.9, 4.8, 3.7, 4, 4), threat = c("1.4", 
"1.5", "1.6", "1.5", "1.9", "1.4", "1.8", "1.8", "1.3", "1.5", 
"1.3", "1.2", "1.3", "1.2", "1.2", "1.5", "1.5", "1.4", "1.5", 
"1.2", "5.6", "3.2", "5.2", "2.9", "4.0", "3.4", "5.6", "3.5", 
"5.5", "6.6", "8.0", "7.8", "7.1", "4.5", "6.3", "6.7", "6.2", 
"5.0", "6.5", "5.4"), arousal = c("1.7", "1.9", "2.2", "2.1", 
"1.8", "2.0", "2.0", "2.3", "2.2", "2.0", "5.3", "4.8", "4.5", 
"3.9", "4.0", "4.5", "4.6", "3.3", "4.2", "3.2", "4.7", "3.2", 
"4.2", "3.0", "3.4", "3.1", "5.2", "3.8", "4.4", "5.3", "6.6", 
"6.2", "6.0", "4.9", "5.2", "6.5", "4.8", "4.0", "5.1", "4.6"
)), row.names = c(NA, -40L), class = "data.frame")
intensity_plot<- ggplot(freq_intensity, aes(x= reorder (category, -intensity), y=intensity))+
  stat_summary(fun.y="mean", geom="bar") +
  stat_summary(fun.data = mean_cl_normal, fun.args = list(mult=1), geom = "errorbar", width=0.3, size=0.7) +
  geom_jitter(colour="limegreen",shape=16,size=1, position=position_jitter(0.2))+
  #facet_wrap(~groups_all)+
  ggtitle("") +
  xlab("") + ylab("Mean intensity") +
  theme_bw(base_size = 10) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
  panel.border = element_blank(),
  axis.line = element_line())

print(intensity_plot)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
SophieMQ
  • 55
  • 7

1 Answers1

2

Add fill = category and then use scale_fill_manual.

library(ggplot2)

ggplot(freq_intensity, aes(x = reorder(category, -intensity),
                          y=intensity, fill = category))+
  stat_summary(fun.y="mean", geom="bar") +
  stat_summary(fun.data = mean_cl_normal, fun.args = list(mult=1), 
               geom = "errorbar", width=0.3, size=0.7) +
  geom_jitter(colour="limegreen",shape=16,size=1, position=position_jitter(0.2))+
  ggtitle("") +
  xlab("") + ylab("Mean intensity") +
  theme_bw(base_size = 10) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        axis.line = element_line()) +
  scale_fill_manual(values=c("#dda832", "#165e70", "#d5927c", "#4f9694"))

enter image description here

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Thank you so much! I tried adding both fill = category and scale_fill_manual but not at the same time :). Much appreciated! – SophieMQ Feb 09 '21 at 04:08
  • Oh I didn't realise! Thanks for letting me know :) (sorry I'm quite new to this platform) – SophieMQ Feb 09 '21 at 06:26