[英]How to change axis scale in lattice::xyplot
我對R比較陌生,並嘗試使用點陣xy繪圖制作一個圖。
這是當前的圖形和數據框:
Plot9Pn <- c(46, 33, 28)
Plot11Pn <- c(20, 18, 10)
Plot14Pn <- c(34, 28, 26)
Plot15Pn <- c(57, 33, 12)
Plot9Pr <- c(30, 46, 95)
Plot11Pr <- c(8, 11, 14)
Plot14Pr <- c(10, 46, 46)
Plot15Pr <- c(15, 37, 110)
Pn.vs.Pr.dat <- data.frame (x=rep (2009:2011, 8), y=c(Plot9Pr, Plot9Pn, Plot11Pr, Plot11Pn, Plot14Pr, Plot14Pn, Plot15Pr, Plot15Pn),
var=factor(rep(c("Pram","Pnem"), each=3)),
graph=factor (rep (c(" A. Plot 9", "B. Plot 11", "C. Plot 14", "D. Plot 15"), each=6)))
require(lattice) # no need to install but loading is required.
xyplot (y ~ x | graph, groups=var, data=Pn.vs.Pr.dat, type="o", pch=my.pch, lty=1,
main="Changes in P. nemorosa vs. P. ramorum occurence", layout=c(1, 4), as.table=T, xlab="Year", ylab="No. Positive",
strip.left=T, strip=F,
key=list (columns=2, text=list (my.text), points=list (pch=my.pch, col=my.col),
lines=list (lty=1, col=my.col)))
我希望X軸在一年中僅顯示三個刻度,並更改Y軸的比例以適合每個圖。
只需將其添加到xyplot參數即可:
... , scales=list(x=list(at=c(2009,2010,2011), labels=c(2009,2010,2011))),
一般原則是,參數作為列表傳遞,第一個參數中的一個或兩個都可以是'x'或'y',並且您可以在?xyplot
找到可用的參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.