0

I am trying to change the colour scheme by category for this time series in ggplot in R. I do not like the default colour scheme as for the number of categories (9) the colours get hard to distinguish, for lots of data (414 data points).

g = ggplot(data=NCARsOld,aes(x=`Date Reported`,
                         y=as.numeric(`No. of Days Opened`),
                         colour=factor(NCARsOld$`Subject/ 
    Category`))) + geom_point() +  scale_fill_discrete("Multi word 
    title", breaks=c(1:length(subjects)), labels=subjects)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
therickster
  • 111
  • 6
  • 1
    Can you include the information necessary for us to reproduce the problem you're having? – teunbrand Jul 23 '21 at 16:52
  • It's easier to help you if you include a simple reproducible example with sample input that can be used to test and verify possible solutions. Here is how to do it - https://stackoverflow.com/q/5963269/12382064 – KacZdr Jul 23 '21 at 17:08

1 Answers1

0

Define a color vector like this:

color_vector <- c('#9da337',blue,green) #etc

Then add scale_color_manual(values = color_vector)

g <- ggplot(data=NCARsOld,aes(x=`Date Reported`,
                         y=as.numeric(`No. of Days Opened`),
                         colour=factor(NCARsOld$`Subject/ 
    Category`))) + 
      scale_color_manual(values = color_vector) +
      geom_point() +  
      scale_fill_discrete("Multi word title", breaks=c(1:length(subjects)), labels=subjects)

Here's where I learned how to use it: https://www.r-bloggers.com/2019/05/a-detailed-guide-to-ggplot-colors/

Dharman
  • 30,962
  • 25
  • 85
  • 135