[R] Graph many points without hiding some

Claudia Beleites cbeleites at units.it
Thu Mar 31 10:59:39 CEST 2011


> AFAIK, base graphics doesn't have alpha transparency available,
They do:
plot(rnorm(x,mean=19),rnorm(x),xlim=c(16,24), cex = 0.2, col = "#00000040")

Also, have a look at hexbin (with very small bins). Here's a ggplot2 
version that gives different colors to the different groups of data:
https://github.com/hadley/ggplot2/wiki/Case-Study%3A-Raman-Spectroscopic-Grading-of-Gliomas

If I have large differences in size of the groups, I sometimes combine 
the hexbin output for the large groups with points for the small groups 
(see the attachment if the file makes . IN ggplot2, you can just add 
them by geom_point () after the
geom_hex.

df <- data.frame (x = rnorm (10000), y = rnorm (10000),
  grp = factor (sample (3, 10000, prob = c(1, 1, 1000), replace = TRUE)))

ggplot (df [FALSE,], aes (x = x, y = y, col = grp)) +
	stat_binhex (data = subset (df, grp == 3), col = NA) +
	geom_point (data = subset (df, ! grp == 3)) +
	scale_fill_gradient (low = "white", high = "black")

Claudia
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tmp.pdf
Type: application/pdf
Size: 82515 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110331/0bda31fc/attachment.pdf>


More information about the R-help mailing list