0

I want the lines and points on my line graph to both be the same colour, organised by cell type according to the figure legend. For cell types 'M' and the 'EPC's the lines aren't the correct colour, but the points are... where am I going wrong?!

This is my code:

myrYFP_18.7_ABA_2_reordered <- myrYFP_18.7_ABA_2
myrYFP_18.7_ABA_2_reordered$Cell.type <- factor(myrYFP_18.7_ABA_2_reordered$Cell.type,  
                                levels = c("GC_1", "GC_2", "NC_1", "NC_2", "NC_3", "M", 
"EPC_1", "EPC_2", "EPC_3"))

cbPalette <- c("#0033FF", "#0099FF", "#FFCC00", "#FF9900", "#FF6600", "#FF00FF", "#CCFF00", 
"#66FF00", "#33CC33")

myrYFP_18.7_ABA_volume_change_plot <- ggplot(data=myrYFP_18.7_ABA_2_reordered, aes(x=Time, 
y=Percentage.volume.change, group=Cell.ID)) +
geom_point(aes(colour=Cell.type)) +
geom_line(aes(colour=Cell.type)) +
scale_fill_discrete(name="Cell type") +
scale_colour_manual(values=cbPalette) +
ylim(-40, 20) + xlim(0,120)

And this is my line graph:

Cell volume change plot

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • 5
    It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample inputthat can be used to test and verify possible solutions. – MrFlick Aug 22 '22 at 14:28
  • 1
    Try removing `colour=Cell.type` from the geoms point and line and put it in the initial call to `ggplot`. And there's no need for the `scale_fill_*`, the `fill` aesthetic is not mapped to a variable. – Rui Barradas Aug 22 '22 at 14:40
  • 2
    Are you _sure_ there is only one Cell.type per Cell.ID? – Allan Cameron Aug 22 '22 at 14:41
  • 1
    As Allan alludes to, I suspect this is caused by an interaction between `group = Cell.ID` and `colour = Cell.type`. The question is, whether the first argument is necessary here, as you are grouping by cell type already. Try just `colour = ...` or `group = ...`. – Oliver Aug 22 '22 at 14:44

0 Answers0