Tobitor
Tobitor

Reputation: 1508

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?

Upvotes: 3

Views: 7939

Answers (1)

DaveArmstrong
DaveArmstrong

Reputation: 21982

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

Upvotes: 2

Related Questions