I am using the SPEI package along with its sample monthly data of 32 years. I want to modify the x-axis labels to reflect the years not the numbers. However, the hard coded plotting function won't allow me to do this. I tired to extract the SPEI$fitted
data and tried to replicate the same plot with ggplot but did not succeeded. Here is the sample code
install.packages("SPEI")
library(SPEI)
data("wichita")
wichita$PET=hargreaves(Tmin=wichita$TMIN, Tmax = wichita$TMAX, lat = 37.64)
wichita$BAL=wichita$PRCP - wichita$PET
SPEI_12=spei(wichita[,"BAL"],12)
plot.spei(SPEI_12, main = 12-Month SPEI)
Any help would be appreciated. I want to produce a graph like attached.
I did not quite understand the
plot.spei
function, so I usedggplot2
.Basically I built a data frame with ts of the fitted values and created a color/fill condition for positive (
pos
) or negative (neg
) values.Edit: An additional idea.