What are the default plotting colors in R or ggplot2?
ggplot2, plot, r
Solution
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
Problem
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!