I'm trying to transform my primary axis to make all the data readable in relation to the secondary axis. Here's the code I'm using:
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"))
As you can see, it's hard to make out trends, especially for the precipitation data. Is there a way to "spread out" the data for the primary axis or is there a better way of going about this?
Any help will be greatly appreciated!