35

I'm plotting in ggplot2 and want to add some lines that are colored the same as the points. Can anyone tell me what the default color codes are when plotting in R? For example, what are the codes for the following 6 colors:

df <- structure(list(type = structure(1:6, .Label = c("a", "b", "c", 
"d", "e", "f"), class = "factor"), value = 1:6), .Names = c("type", 
"value"), class = "data.frame", row.names = c(NA, -6L))

library(ggplot2)
ggplot(df, aes(x=value, y=value, color=type)) + geom_point(shape=21, size=4)

Thanks!

Thomas
  • 2,484
  • 8
  • 30
  • 49
  • 1
    I'll add that http://imagecolorpicker.com/ is a good tool to know about, but Didzis's answer is sufficient in this case. – rsoren Aug 08 '14 at 19:46
  • 2
    See: http://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette – MrFlick Aug 08 '14 at 19:46

1 Answers1

130

To see what colors are used to make your plot you can use function ggplot_build() and then look at data part of this object (in column colour are codes).

p <- ggplot(df, aes(x = value, y = value, color = type)) +
    geom_point(shape = 21, size = 4)

ggplot_build(p)$data
# [[1]]
#    colour x y PANEL group
# 1 #F8766D 1 1     1     1
# 2 #B79F00 2 2     1     2
# 3 #00BA38 3 3     1     3
# 4 #00BFC4 4 4     1     4
# 5 #619CFF 5 5     1     5
# 6 #F564E3 6 6     1     6
zx8754
  • 52,746
  • 12
  • 114
  • 209
Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201