2

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?

Tobitor
  • 1,388
  • 1
  • 23
  • 58
  • 1
    `ggplot() + geom_jitter(alpha = .01)` should work too. – mrhellmann Jan 15 '21 at 19:08
  • 1
    it would be helpful to have some sort of example data. I'm guessing `cloudCover` and `solar_energy` are discreet and `day_night` is categorical / binary? What are you trying to achieve? To call `geom_points` and `geom_jitter` on the same data does not make sense to me, as one is better suited for a discreet y-axis (`geom_points()`) and one for categorical data (`geom_jitter()`). – randomchars42 Jan 15 '21 at 19:13
  • Yes, this was the problem @randomchars42. And you are also right regarding the types of the variables. The first comment solved the problem :-) Thanks! – Tobitor Jan 15 '21 at 19:15

1 Answers1

2

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
DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25