Transforming a color scale

[This article was first published on is.R(), and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In developing plots, I often use color (or “colour” in ggplot2 parlance) to reflect values of a third, non-X/Y, variable. Depending on the distribution of this Z variable, however, the effective color range can be narrow, making it difficult to discriminate between Z values, as in this plot:

As you can see, the bulk of the points are in the middle, yellow/white range, while green/blue and orange/red only appear near the edges. This is as it should be, since Z = X * Y, and there are relatively few extreme values. However, I am, in a sense, “wasting” a lot of the color range available to me. Fortunately, the package scales offers a function called trans_new(), which permits one to apply any function on the distribution, as I do below. (Thanks to “mnel” at stackoverflow.com.)

To leave a comment for the author, please follow the link and comment on their blog: is.R().

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)