[R] Graphing: plot 3rd variable based on color gradient

hadley wickham h.wickham at gmail.com
Thu Aug 14 21:43:20 CEST 2008


On Thu, Aug 14, 2008 at 2:30 PM, Jason Pare <jay.pare at gmail.com> wrote:
> Hello,
>
> I am searching for the best method to plot two variables with points
> whose output color depends on the size of a third variable. For
> example, the darkness of the x-y point would increase incrementally
> based on the size of the z value, similar to the colramp parameter in
> geneplotter. This would be analagous to symbols(), except changing the
> selection from the color gradient rather than the size of the plotted
> shape. The closest I have come so far is the levelplot() function, as
> below:
>
> graphdata <- alldata[,c("x","y", "size")]
> levelplot(size ~ x * y, data=graphdata)
>
> However, since I only have 147 total observations, the graph produced
> by levelplot() is mostly white space. Is there either a function that
> would produce this in a more visually digestible form, or a parameter
> I can use with levelplot to accomplish this?

install.packages("ggplot2")
library(ggplot2)

qplot(x, y, data=graphdata, colour = size)
qplot(x, y, data=graphdata, size = size)
qplot(x, y, data=graphdata, full = size, geom="tile")

Learn more at http://had.co.nz/ggplot2

Hadley


-- 
http://had.co.nz/



More information about the R-help mailing list