[R] How do I do a pretty scatter plot using ggplot2?
R. Michael Weylandt
michael.weylandt at gmail.com
Sat Mar 10 02:07:19 CET 2012
That doesn't really seem to make sense to me as a graphical
representation (transforming adjacent y values differently), but if
you really want to do so, here's what I'd do if I understand your goal
(the preprocessing is independent of the graphics engine):
DAT <- data.frame(x = runif(1000, 0, 20), y = rcauchy(1000)^2) # Nice
# split y based on some x binning and assign empirical quantiles of each group
DAT$yquant <- with(DAT, ave(y, cut(x, seq(0, 20, 5)), FUN =
plot(yquant ~ x, data = DAT)
p <- ggplot(DAT, aes(x = x, y = yquant)) + geom_point()
PS -- I see Josh Wiley just responded pointing out your requirements
#1 and #2 are incompatible: I've used 1 here.
On Fri, Mar 9, 2012 at 7:37 PM, Michael <comtech.usa at gmail.com> wrote:
> Hi all,
> I am trying hard to do the following and have already spent a few hours in
> 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:
> 1. Uniform bin size on the x-axis;
> 2. Equal number of observations in each bin;
> How to do that in R? I guess for the sake of prettyness, I'd better do it
> in ggplot2?
> Thank you!
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help