Search code examples
rggplot2jitter

R - ggplot - jitter plot with transparent data points


I want to get a jitter plot with transparent data points and I use this code:

p<-ggplot(house_data,aes(x=cloudCover, y=solar_energy, color = day_night)) 
p<-p+geom_jitter()
p<-p+geom_point(alpha = 0.01)
p

I get a jitter plot but unfortunately I do not get transparent data points. I experimented with different values for alpha but the plot stays the same... What is wrong with my code?


Solution

  • You should be able to use position_jitter in the point geometry. The width and height parameters are the amount of jitter on the x- and y-axes respectively:

    p<-ggplot(house_data,aes(x=cloudCover, y=solar_energy, color = day_night)) 
    p<-p+geom_point(alpha = 0.01, position=position_jitter(height=.5, width=.5))
    p