Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rug plot does not work when specifying alpha colors?

This works:

plot(1:10, col=rgb(0,0,0,1))
rug(1:10, col=rgb(0,0,0,1))

And this does not work (no rugs are additionally plotted):

plot(1:10, col=rgb(0,0,0,0.9))
rug(1:10, col=rgb(0,0,0,0.9))

Why? And how can I fix this?

The reason why I need this is because I would like to add alpha colors so that overlapping "rugs" are darker. Without beeing able to specify alpha colors, I am only able to plot this:

plot(rep(1:10,100), rep(1:10,100), col=rgb(0,0,0,1))
rug(jitter(rep(1:10,100)), col=rgb(0,0,0,1))

enter image description here

like image 209
Giuseppe Avatar asked Oct 19 '22 22:10

Giuseppe


1 Answers

# This is quite easy to do with ggplot2
# data
df = data.frame(x = rep(1:10,100), y = rep(1:10,100))
# code
library(ggplot2)
ggplot(df, aes(x=x, y=y)) + 
  geom_point() + 
  geom_rug(sides="b", position="jitter", alpha=0.2, colour="blue") +
  scale_x_continuous(breaks=seq(0,10,by=2)) +
  scale_y_continuous(breaks=seq(0,10,by=2))

enter image description here

like image 98
KFB Avatar answered Nov 03 '22 21:11

KFB