Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See the specific color names from one existing palette in ggplot 2

Tags:

r

colors

ggplot2

I am looking to see the color name from set1 palette. I need to use number 4 and 5 on my graph, that are the violet and orange one. I don't know their code. Please point me to where I could find their name or code. Thanks a lot.

The set1 I am mentioning is here:

https://learnr.wordpress.com/2009/04/15/ggplot2-qualitative-colour-palettes/

Thanks so much for any suggestion

like image 908
Little Bee Avatar asked Jun 03 '16 21:06

Little Bee


People also ask

How do I specify colors in ggplot2?

A color can be specified either by name (e.g.: “red”) or by hexadecimal code (e.g. : “#FF1234”).

How do I find colors 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.

Is ggplot colorblind friendly?

More specifically, ggpubfigs contains six color palettes that are colorblind friendly and aim to increase the accessibility of scientific figures and eight themes that modify 21 parameters of a default ggplot2 figure.


1 Answers

You can find out the code by ggplot_build.

# fake data
df <- data.frame(x=1:8, y=1, col=letters[1:8])

# Construct the plot
g <- ggplot(df, aes(x=x, y=y, color=col)) + geom_point(size=5) +
  scale_color_brewer(palette="Set1")

g

enter image description here

# Retrieve the color
colors <- ggplot_build(g)$data[[1]]$colour

# Double check
plot(df$x, df$y, col=colors, pch=20, cex=5)

enter image description here

# color 4 and 5
colors[4:5]
[1] "#984EA3" "#FF7F00"
like image 177
JasonWang Avatar answered Nov 10 '22 13:11

JasonWang