Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change line and shape colours in ggplot2?

Tags:

r

ggplot2

I have a data frame like this one:

x <- data.frame(time = c('1', '2', '3'), perc = c(0.2, 0.4, 0.6, 0.3, 0.55, 0.69, 0.2, 0.22, 0.35), type=c(rep('a', 3), rep('b', 3), rep('c', 3)))

and want to do a plot like this (below) but using these different colors c('#0023a0', '#f9a635', '#bebec0'):

ggplot(x, aes(time, perc, group=type, colour=type, shape=type)) + geom_point(size=4) + geom_line(size=1)

enter image description here

I have already tried different ways using scale_colour_hue, scale_shape_discrete and scale_fill_manual, but without any success.

like image 618
Davi Moreira Avatar asked Feb 19 '23 14:02

Davi Moreira


1 Answers

What exactly did you try? This seems to work for me:

ggplot(x, aes(time, perc, group = type, pch = type, colour = type)) + 
  geom_point() +
  geom_line() +
  scale_colour_manual(values= c('#0023a0', '#f9a635', '#bebec0'))

enter image description here

like image 130
Chase Avatar answered Mar 04 '23 13:03

Chase