0

I want to make a chart that matches average temperatures with precipitation, just like what is in this link https://www.r-bloggers.com/part-3a-plotting-with-ggplot2/. Average temperatures are made with geom_violin and precipitation with geom_point. I used my data and I did that chart. The problem is that I do not want the values with 0.0 of precipitation to appear on the chart. Basically what I did was put a condition in the part that refers to the size of the points representing the precipitation, but didn't work. I've tried it in other ways but nothing works.

ggplot(weather,aes(x = month, y = temp)) +
geom_violin(fill = "orange") +
geom_point(aes(size = precipitation >0), colour = "blue", 
position="jitter")+
ggtitle ("Temperature by month") +
xlab("Month") +  ylab ("temperature ( ºC )")

Any help will be appreciated, Thanks

  • Please provide some data so we can reproduce your graph. See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – user3640617 Aug 04 '17 at 12:13

1 Answers1

1

Without seeing your data and assuming that precipitation is a variable in your data set weather, you could subset your data before plotting it which would remove values under 0 from the plot.

ggplot(weather, aes(x = month, y = temp)) +
geom_violin(fill = "orange") +
geom_point(data = weather[which(weather$precipitation>0),], 
            aes(size = precipitation >0), colour = "blue", 
position="jitter") +
ggtitle ("Temperature by month") +
xlab("Month") +  
ylab ("temperature ( ºC )")
kfurlong
  • 303
  • 2
  • 8
  • Yes precipitation it's a variable in my data set. But if i do a subset, i will delete some temperature values from my data set. I want to plot the precipitation without zero values, but i dont want to delete the rows that contain zero precipitation because. If i do that i will delete some temperature values. – mauricio santos Aug 04 '17 at 13:10
  • Okay, I'll edit my above answer. The data source you pass into the `ggplot` command will get passed down to all of the `geom_` layers unless you specify otherwise. – kfurlong Aug 04 '17 at 13:47