about colors in the plot

32 views
Skip to first unread message

lily li

unread,
Jun 30, 2016, 7:06:10 PM6/30/16
to ggp...@googlegroups.com
Hi ggplot users,

If I use automatic color function, rather than set different colors myself, I found that the automatic colors are changing with a gradient. It is not very differentiating. Is there a way to let the colors more distinct? I have many different classes, so setting colors manually is not convenient. Thanks for your help.

Brandon Hurr

unread,
Jun 30, 2016, 7:08:04 PM6/30/16
to lily li, ggp...@googlegroups.com
Could you provide an example of what you're doing. It's obvious you're using a gradient, but which one and how are you using it? 

Thanks, 
B

On Thu, Jun 30, 2016 at 4:05 PM, lily li <choc...@gmail.com> wrote:
Hi ggplot users,

If I use automatic color function, rather than set different colors myself, I found that the automatic colors are changing with a gradient. It is not very differentiating. Is there a way to let the colors more distinct? I have many different classes, so setting colors manually is not convenient. Thanks for your help.

--
--
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/d/optout.

lily li

unread,
Jun 30, 2016, 7:50:11 PM6/30/16
to Brandon Hurr, ggp...@googlegroups.com
Hi Brandon,

Here is an example. If I have many variables with different classes, and use colour function to automatically set the colors, they are not very distinctive. How to let them more recognizable? Thanks.

df <- data.frame("ID"=1:21,"Age"=10:30,"Height"=155:175,'Score'=34:54, 
                stringsAsFactors=FALSE)
pl = ggplot(df,aes(ID,Score))+geom_point(aes(colour=factor(Age)))
show(pl)

Ben Bolker

unread,
Jun 30, 2016, 8:31:26 PM6/30/16
to ggp...@googlegroups.com

It's very difficult to pick 21 distinguishable colours in any case.
You can search for "iwanthue" on Stack Overflow e.g.
http://stackoverflow.com/search?q=%5Br%5D+iwanthue

http://stackoverflow.com/questions/21352683/randomising-qualitative-colours-for-large-sets-in-ggplot/21374290#21374290

but most of the answers there say that if you want to distinguish that
many categories you'll have to find another strategy (faceting, direct
labeling, ...)

good luck
Ben Bolker
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@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
> <mailto:ggplot2+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> --
> 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
> <mailto:ggplot2+u...@googlegroups.com>.

Wouter van der Bijl

unread,
Jul 2, 2016, 6:27:03 AM7/2/16
to ggplot2
I would recommend the viridis package for continuous data. It contains scale_color_viridis() that you can add to your plot. It has a lot more range than the default ggplot blues.

Reply all
Reply to author
Forward
0 new messages