I'm trying to use ggplot
to create a pseudo-boxplot
by way of colour/transparency but am struggling a little. The idea is that for any point on the x axis, the more number of times a specific y value occurs, the darker that (x,y) point should be. To add to the complication, I don't have a count for each (x,y), but instead I have a count for (x , ymin:ymax)
which means that this count holds for all points between (x,ymin) and (x,ymax)
Searching seems to be a little tricky and I"m unable to unearth anything I can use. The closest I could get by myself was as below, however this takes very long for larger datasets.
library(ggplot2)
set.seed(1)
(d <- data.frame(cbind(x = sample(1:3, 10, replace = TRUE), y = sample(3:8, 10, replace = TRUE)), fac = sample(1:3, 10, replace = TRUE)))
p1 <- ggplot()
for ( i in seq(nrow(d)))
{
p1 <- p1 + geom_rect(
data=d[i,],
aes(
xmin = fac - .4,
xmax = fac + .4,
ymin = x,
ymax = y),
alpha = .25
)
}
Any suggestions? I'd prefer a ggplot
solution. Thanks
Update on 23 Nov 13, With Troy's help I've reached here. The only issues now is that the legend is ranging between the t values for each rectangle, whereas it should range from the cumulative t at an x,y.
library(ggplot2)
set.seed(1)
d <- data.frame(cbind(x = sample(1:3, 6, replace = TRUE),
ymin = sample(3:8, 6, replace = TRUE),
ymax = sample(3:8, 6, replace = TRUE),
t = sample(3:8, 6, replace = TRUE)/10
))
ggplot(data=d) +
geom_rect(aes(xmin=x-0.4,xmax=x+0.4,ymin=ymin,ymax=ymax,alpha=t),fill="red")