簡體   English   中英

在最小值處開始y軸,在0處開始x軸,並使用R中的matplot()使它們相交

[英]starting the y-axis at a minimum value, the x-axes at 0, and making them intersect using matplot() in R

這個問題上說我現在的問題被這個問題回答了; 但是建議的代碼對我來說還遠遠不夠。 這些圖表需要適合科學出版,因此yaxs = "i"xaxs = "i"的效果不適合我需要生成的結果。

第二個鏈接中顯示的圖表看起來不錯,可以很好地完成我所要完成的工作,但是當我對不以0開始的數據使用類似的代碼時:

matplot(times, cbind(a, b, c),
    pch = 1,
    col = c("red", "blue", "green"),
    lty = c(1, 1, 1),
    xlab = "Time (s)",
    ylab = "Flourescense Yield (RFU)",
    main = "test",
    xlim = c(0 , max(times)),
    ylim = c(min(a, b, c) - 0.1* min(a, b, c), max(a, b, c) + 0.1* max(a, b, c)),
    axes = FALSE)
axis(1, pos = 0, at = 0: round(times))
axis(2, pos = 0, at = round(min(a, b, c)): round(max(a, b, c)))

legend("topright", y =NULL, c("Biocomposite 1", "Biocomposite 2", "Biocomposite 3"),
       text.col = c("red", "blue", "green"))

我得到以下圖表:

在此處輸入圖片說明

我簡化了代碼,因此不使用實際數據,而是使用以下對象:

a <- sample(1:100, 10, replace = TRUE)

b <- sample(1:100, 10, replace = TRUE)

c <- sample(1:100, 10, replace = TRUE)

times <- c(0:9)

我想讓軸在(0,6)處交叉,水平刻度線以5的倍數遞增。

排序方面的任何幫助都將很棒!

以下任何一項都可以滿足您的要求?

方法1:規則軸(xaxs ='r'),帶有框?

dev.new()
par(xaxs="r", yaxs="r")
plot(times, a, pch=1, col="red", axes=F, xlab=NA, ylab=NA)
axis(side=1, at=times)
mtext("Times (s)", side=1, line=2.5)
axis(side=2, at=seq(0,100,10))
mtext("Flourescense Yield", side=2, line=2.5)
points(times, b, col="blue")
box()

方法2:或更緊的軸(xaxs ='i'),但x和y限制略有誇張,並帶有一個框?

dev.new()
par(xaxs="i", yaxs="i")
plot(times, a, pch=1, col="red", axes=F, xlab=NA, ylab=NA,
     xlim=c(-.5,9.5), ylim=c(-2,102))
axis(side=1, at=times)
mtext("Times (s)", side=1, line=2.5)
axis(side=2, at=seq(0,100,10))
mtext("Flourescense Yield", side=2, line=2.5)
points(times, b, col="blue")
box()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM