我想创建一个与平均温度和降水相匹配的图表,就像这个链接https://www.r-bloggers.com/part-3a-plotting-with-ggplot2/中的内容一样。平均温度用geom_violin和降水与geom_point。我使用了我的数据而且我做了那张图表。问题是我不希望图表上出现降水量为0.0的值。基本上我所做的是在部分中提出了一个条件,它指的是代表降水的点的大小,但是没有用。我已经尝试过其他方式,但没有任何作用。
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 )")
任何帮助将不胜感激, 感谢
答案 0 :(得分: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 )")