Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the default plotting colors in R or ggplot2? [duplicate]

Tags:

plot

r

ggplot2

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!

like image 331
Thomas Avatar asked Aug 08 '14 19:08

Thomas


People also ask

What are the default colors in ggplot2?

By default, ggplot2 chooses to use a specific shade of red, green, and blue for the bars.

How do I color data in R?

In R, colors can be specified either by name (e.g col = “red”) or as a hexadecimal RGB triplet (such as col = “#FFCC00”). You can also use other color systems such as ones taken from the RColorBrewer package.

How do you change the color of a title in R?

To change the color of Title and Subtitle, We simply add a color parameter to element_text() function.


1 Answers

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 
like image 100
Didzis Elferts Avatar answered Oct 08 '22 20:10

Didzis Elferts