3

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?

3
  • 2
    ggplot(<as as above>) + geom_jitter(alpha = .01) should work too. Commented Jan 15, 2021 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()). Commented Jan 15, 2021 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! Commented Jan 15, 2021 at 19:15

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.