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!
By default, ggplot2 chooses to use a specific shade of red, green, and blue for the bars.
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.
To change the color of Title and Subtitle, We simply add a color parameter to element_text() function.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With