I am using SPEI package that comes with data and some plotting functionality. I want to format the x-axis of the plot to reflect month-year (or only year) instead year sequence.
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_12,main = "12 month SPEI")
#I tried
SPEIData=SPEI_12$fitted
myDates=as.data.frame(seq(as.Date("1980-01-01"), to=as.Date("2011-10-31"), by="month"))
names(myDates)= "Dates"
plot(SPEIData,, axes=FALSE, axis.Date(1, at=myDates$Dates, format = "%m-%Y"),col=ifelse(SPEIData_12 < 0,"red","blue"))
The plot should somewhat look like this
Aucun commentaire:
Enregistrer un commentaire