[R] how to best present concentrated data points/ ggplot2
izahn at psych.rochester.edu
Wed Jul 6 05:45:37 CEST 2011
Strategies for dealing with overplotting include transparency, size,
and jittering. In your example you'll probably need all three.
m + geom_point(aes(x = expo, y = ze, shape = type),
size = 1, alpha = .2, position = position_jitter(width = 0, height
= 5)) + geom_density()
seems to work OK.
On Tue, Jul 5, 2011 at 8:46 PM, Yang Lu <Yang.Lu at williams.edu> wrote:
> Hi all,
> I am trying to plot a weighted density plot for two different types and want to show the data points on the x axis.
> The code is as follows. The data points are very concentrated. Is there a better way to present it( should I set the alpha value or something else)?
> x <- rnorm(10000)
> a <- rnorm(5000)
> b <- rnorm(5000)
> weights.x <- abs(a/sum(a))
> weights.y <- abs(b/sum(b))
> weight <- c(weights.x, weights.y)
> ze <- rep(0,10000)
> type <- c(rep("a",5000), rep("b",5000))
> d <- data.frame(expo = x, weight = weight, type = type, ze = ze)
> m <- ggplot(d, aes(x = expo, group = type, col = type, weight = weight))
> m+geom_density()+geom_point(aes(x = expo, y = ze, shape = type))
> 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.
University of Rochester
Department of Clinical and Social Psychology
More information about the R-help