Reputation: 21
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
Upvotes: 0
Views: 2670
Reputation: 323
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 )")
Upvotes: 1