Default colors

20 views
Skip to first unread message

abi...@sent.com

unread,
May 16, 2013, 12:56:14 PM5/16/13
to ggp...@googlegroups.com
Good day all,

Can someone please tell me what are the default colors codes or names in ggplot2 ?

In order to use the same color code as for plots done elsewhere (with ggplot2) I need to change the order of the colors so that they fit with the factor I am using. I am not allowed to  change the factor order.

So I do need to define manually the colors but using the same colors that are used by default.

Thanks for any help, JL

Ito, Kaori (Groton)

unread,
May 16, 2013, 2:22:00 PM5/16/13
to abi...@sent.com, ggp...@googlegroups.com

I am not sure this is the best way, but you can find what colors are used in a plot by ggplot_build().

For example, you can write such as:

 

p <- ggplot(data=Data, aes(x=x1, y=y1, color=group)) + geom_point()

layer.info <- ggplot_build(p)

layer.info$data[[1]]

    colour  x          y PANEL group

1  #F8766D  1  0.6770207     1     1

2  #F8766D  2  0.2741748     1     1

3  #F8766D  3 -0.8573757     1     1

4  #F8766D  4  1.8533354     1     1

5  #00BA38  5  1.2952191     1     2

6  #00BA38  6  3.7527824     1     2

7  #00BA38  7  5.3196280     1     2

8  #00BA38  8  3.3043251     1     2

9  #619CFF  9  2.7967956     1     3

10 #619CFF 10  3.9842329     1     3

11 #619CFF 11  5.7358461     1     3

12 #619CFF 12  7.1017455     1     3

 

And you can find the hex color numbers (#F8766D  for group 1, #00BA38 for group 2 #619CFF for group 3).

--Kaori

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jean-Louis Abitbol

unread,
May 16, 2013, 4:49:44 PM5/16/13
to ggp...@googlegroups.com
Thanks a lot Mary and Kaori.

Got the color codes with

library(ggplot2)
x1 <- seq(1:8)
y1 <- seq(1:8)
group <- factor(seq(1:8))
df <- data.frame(x1,x2,group)
p <- ggplot(data=df, aes(x=x1, y=y1, color=group)) + geom_point(size=4)
+
theme_bw()
p
layer.info <- ggplot_build(p)
layer.info$data[[1]]

Best wishes, JL
Reply all
Reply to author
Forward
0 new messages