How to do a pretty scatter plot in R? I am trying hard to do the following and have already spent a few hours in vain:
I wanted to do the scatter plot.
But given the high dispersion on those dots, I would like to bin the x-axis and then for each bin of the x-axis, plot the quantiles of the y-values of the data points in each bin:


*

*Uniform bin size on the x-axis;

*Equal number of observations in each bin;


(These two are separate cases.)
How to do that in R? I guess for the sake of prettyness, I'd better do it in ggplot2?
The origin of this problem was that a plain scatter plot with too many points with high dispersion generated too many points flying all over places.
We are trying to smooth the charts a bit...
Any good recommendations?
How about "plot the quantiles of each bin"?
But how are the quantiles plotted? Shall I specify 50% quantile, etc?

[p.s. Update 3/11/2011]: I am trying the following following R-help posts:
DAT <- data.frame(x = runif(1000, 0, 20), y = rnorm(1000))
DAT$xbin <- with(DAT, cut(x, seq(0, 20, 2)))

p <- ggplot(DAT, aes(x = x, y = y)) + geom_point(alpha = 0.2) +
stat_quantile(aes(colour = ..quantile..), quantiles = seq(0.05, 0.95,
by=0.05)) + facet_wrap(~ xbin, scales = "free")
print(p)

My questions are:
1) How do I make it "equal number of points" in each bin along the x-axis? i.e. the original number 2 requirement in my question?
2)
And also, no matter how I changed the quantiles = seq(0.05, 0.95,
by=0.05)) line, 
the number of lines in each bin and the number of legends on the right side of the each plot are different...
What's the catch? Am I missing something here?
I thought the number of quantile lines and the number of legends should be exactly the same, no?
 A: You can to do this in the new version of ggplot2 (0.9).
You can try it out:
library(ggplot2) #make sure the newest is installed

df <- data.frame(v1 = runif(1000), v2 = runif(1000))

bin.plot<-qplot(data=df,
                x=v1,
                y=v2,
                z=v2)


bin.plot+stat_summary_hex(fun=function(z)length(z))


bin.plot+stat_summary2d()(fun=function(z)length(z))


These may also be of interest if you want to bin only on one variable
geom_violin
geom_dotplot

You can also start by binning your data and then jitter it.
The release notes of ggplot2 0.9:
http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf
For development versions of ggplot2
#library(devtools)
#dev_mode()
#install_github("ggplot2")
#library(ggplot2)

A: You may want to look at these two entries from 'SAS and R':
http://sas-and-r.blogspot.com/2011/07/example-91-scatterplots-with-binning.html 
http://sas-and-r.blogspot.com/2011/07/example-92-transparency-and-bivariate.html
They cover the use of binning, transparency and bivariate kernel density estimators for scatter plots of large amounts of data. They might serve as decent starting points.
I'm rather biased against ggplot2, so I won't comment on whether or not you need to use it for prettyness - I find the figures in these entries to be perfectly appealing.
A: It's not really an answer to your question about binning one easy solution in ggplot2 to deal with large amount of data in scatterplots is to use the alpha parameter to set some transparency
> df <- data.frame(v1 = rnorm(100000), v2 = rnorm(100000))
> ggplot(df, aes(x=v1, y=v2)) + geom_point(alpha = .01) + theme_bw()


