[R] how to best present concentrated data points/ ggplot2

Yang Lu Yang.Lu at williams.edu
Wed Jul 6 02:46:52 CEST 2011


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)?

Thanks!

YL

library(ggplot2)

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))



More information about the R-help mailing list