R-Project: How to limit axes in SPI plot? ylim & xlim don't work

二次信任 提交于 2021-02-11 08:59:28

问题


Dear stackoverflow community,

I'm quite new in R and this is my first stackoverflow entry so please show mercy with me if it's not the perfect questioning.

I'm calculating standardized precipitation index (SPI) with the package "SPEI" for a time series of a climate station with 20 years of monthly precipitation data. I have done this for the timescale of 1 and 12 month like this:

spi1 <- spi(SPI_Anu_input_ts[,'PRCP_Anu'], 1)
spi12 <- spi(SPI_Anu_input_ts[,'PRCP_Anu'], 12)

The output of SPI is not a matrix or a dataframe, it's a list. Inside this list under the entry fitted you find a timeseries with the wanted and calculated index values.

To plot these index values you don't have to enter x & y like usual:

plot(x, y, ...)

You can just use the complete list:

par(mfcol=c(2,1))
plot(spi1, 'Anuradhapura, SPI-1')
plot(spi12, 'Anuradhapura, SPI-12')

Then it looks like this:

Plot SPI1 & SPI12

Part of SPI calculation is that the amount of time scale is the first month for the first index value. The precipitation data is starting in Jan 1990. So the indices for SPI1 start in january but for SPI12 start in december (first 11 month are NA).

As you can see in the graphic both x and y axes are shifted. Neither

xlim=as.Date(c("1990-01-01","2017-09-01"))

nor any axes limitation like

ylim=c(-2.5,2.5)

is working to have the same value range in both graphics.

Do anyone know how to solve that?

来源:https://stackoverflow.com/questions/52311811/r-project-how-to-limit-axes-in-spi-plot-ylim-xlim-dont-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!