With all that said, if you do want to do the plot in your way you may need to construct it piece by piece all by YOURSELF. The following code will produce something that is quite similar to what you will get from plot.xts (at least to me). There is no time series structure involved as I am not familiar with it. BTW, the "Canada" data is provided with vars package not with R base installation.
- # Enlarge right margin for additional axis
- par(mar = c(5, 4, 4, 4) + 0.1)
- # Set the limits of axes
- plot(c(0, 84), c(0, 6), type = "n", xlab = "", ylab = "", axes = F, xlim = c(0, 84), ylim = c(-0.5, 6.5))
- # Minor ticks for x-axis
- axis(1, at = c(0:84), labels = F, col = "#BBBBBB")
- # Major ticks for x-axis
- axis(1, at = c(0:21*4), labels = sapply(0:21, function(i) ifelse(i %% 4, NA, 1980 + i)),
- lwd = 1)
- # Y-axis on the left
- axis(2, at = c(0:6), labels = 930 + c(0:6)*5)
- # Corresponding axis title - colored same as data using this axis
- mtext("e", side = 2, line = 3, col = "red")
- # Y-axis on the right
- axis(4, at = c(0:6), labels = c(0:6) + 7)
- # Corresponding axis title - colored same as data using this axis
- mtext("U", side = 4, line = 3, col = "blue")
- # Vertical lines of grid
- abline(v = c(0:21*4), lty = 4, col = "grey")
- # Horizontal lines of grid
- abline(h = c(0:6), lty = 4, col = "grey")
- # Add box to make it more R-style
- box()
- # Plot first series - manually manage the transform of the data
- lines(c(0:83), (Canada[, "e"] - 930)/5, col = "red")
- # Plot second series - manually manage the transform of the data
- lines(c(0:83), Canada[, "U"] - 7, col = "blue")
I am sure there are simpler/better solutions. This just serves as an exmaple showing the super flexibility of R graphic.
I have not tried Rsweave but would probably expect little change in the codes. As far as I am aware of there is no limit on number of packages loaded in older version of R.
Here is my session info:
- sessionInfo()
- # R version 2.15.2 (2012-10-26)
- # Platform: i386-w64-mingw32/i386 (32-bit)
- # locale:
- # [1] LC_COLLATE=English_United States.1252
- # [2] LC_CTYPE=English_United States.1252
- # [3] LC_MONETARY=English_United States.1252
- # [4] LC_NUMERIC=C
- # [5] LC_TIME=English_United States.1252
- # attached base packages:
- # [1] stats graphics grDevices utils datasets
- # [6] methods base
- # other attached packages:
- # [1] xts_0.9-7 zoo_1.7-10
- # loaded via a namespace (and not attached):
- # [1] grid_2.15.2 lattice_0.20-10 tools_2.15.2


雷达卡



京公网安备 11010802022788号







