我正在尝试转换主轴以使所有数据相对于辅助轴可读。这是我正在使用的代码:
ggplot(data = NOAARainfallAirTemp, aes(x = Date)) +
geom_smooth(aes(y = Temp, color ="Temperature"), method = "loess", span = 0.3, fill = "blue") +
geom_point(aes(y = Temp, color = "Temperature"), alpha = 0.3) +
geom_smooth(aes(y = PRCP*6, color = "Precipitation"), method = "loess", span = 0.3, fill = "orange") +
geom_point(aes(y = PRCP*6, color = "Precipitation"), alpha = 0.3) +
scale_x_date(expand = c(0.001,0.001), date_breaks = "3 months", date_labels = "%b%Y", date_minor_breaks = "1 month") +
scale_y_continuous(expand = c(0.001,0.001), sec.axis = sec_axis(~./6, name = "Precipitation")) +
ylab("Temperature (°C)") +
ggtitle("Diagnostics of NOAA Data") +
theme(axis.text.x=element_text(angle = 90, hjust = 0), plot.title = element_text(hjust = 0.5)) +
guides(shape = guide_legend(override.aes = list(shape = 15)), color = guide_legend(override.aes = list(fill = NA))) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_line(colour = "grey"),panel.background = element_blank(), axis.line = element_line(colour = "black"))
如您所见,很难确定趋势,尤其是对于降水数据。有没有一种方法可以“散布”主轴数据,或者有更好的方法呢?
任何帮助将不胜感激!