How to use ggplot2 to display points with gradient color
1
0
Entering edit mode
7.0 years ago
dr.genetics ▴ 60

A typical scatter plot can display a point with (x, y), as we all know. What I want to do is to associate each point with a gradient color for a 3rd dimension variable varying from 0 to 1. For example, with 1 represented with full red and 0 with no red at all for the 3rd dimension.

R • 13k views
ADD COMMENT
3
Entering edit mode
7.0 years ago
VHahaut ★ 1.2k

Something like:

ggplot(data, aes(period, freq, size=copies, color=total_len)) + 
   geom_point() + 
   scale_color_gradient(low="blue", high="red")

from: http://stackoverflow.com/questions/17497479/ggplot-color-fill-and-size-in-geom-point

and using your 0-1 numerical value as the color argument ?

ADD COMMENT
0
Entering edit mode

Incrdibly awesome! It just worked!

ADD REPLY

Login before adding your answer.

Traffic: 2498 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6