2

I am trying to make a manual colour scale for my bar graph using plyr to summarize the data and ggplot2 to present the graph.

The data has two variables:

  1. Region (displayed on the X-axis)
  2. Genotype (displayed by the fill)

I have managed to do this already, however, I have not been able to find a way to personalize the colours - it simply gives me two randomly assigned colours.

Could someone please help me figure out what I am missing here?

I have included my code and an image of the graph below. The graph basically has the appearance I want it to, except that I can't personalize the colours.

ggplotdata <- summarySE(data, measurevar="Density", groupvars=c("Genotype", "Region"))
ggplotdata
#Plot the data
ggplotdata$Genotype <- factor(ggplotdata$Genotype, c("WT","KO"))
Mygraph <-ggplot(ggplotdata, aes(x=Region, y=Density, fill=Genotype)) + 
     geom_bar(position=position_dodge(), stat="identity",
           colour="black",
           size=.2) +
     geom_errorbar(aes(ymin=Density-se, ymax=Density+se),
           width=.2,
           position=position_dodge(.9)) +
     xlab(NULL) +
     ylab("Density (cells/mm2)") +
     scale_colour_manual(name=NULL,
           breaks=c("KO", "WT"),
           labels=c("KO", "WT"),
           values=c("#FFFFFF", "#3366FF")) +
     ggtitle("X") +
     scale_y_continuous(breaks=0:17*500) +
     theme_minimal()
Mygraph

Image of graph

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Liptongal
  • 47
  • 5
  • 4
    As you are using `fill` in the `aes`, you have to use `scale_fill_manual` instead of `scale_color_manual` – dc37 Feb 24 '20 at 15:27
  • 1
    thank you for your help! It works now! – Liptongal Feb 24 '20 at 15:53
  • @Liptongal If you have answered your question, remember to add the response and marked as resolved. So in the future, if someone had the same issue, he would be able to find the response. – German Quinteros Feb 24 '20 at 18:02
  • @GermanQuinteros How exactly do I do that ? Sorry this is my first question.... I can only see the flag icon next to dc's response... – Liptongal Feb 25 '20 at 09:51
  • @Liptongal add an answer. After that on the left top of your answer, you will see a tick grey if you click it, it will be changed to green. – German Quinteros Feb 25 '20 at 13:14

1 Answers1

1

The answer here was to use scale_fill_manual instead, thank you @dc37

Liptongal
  • 47
  • 5