简体   繁体   中英

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

In this question it says my current question was answered by this question ; however the code suggested doesn't go far enough for me. These charts need to be suitable for scientific publication, so the effect of yaxs = "i" and xaxs = "i" is not suitable for what I need to produce.

The charts displayed in the second link look great, and would be up to the job that I am after, however when I use a similar code for data that does not start at 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"))

I get the following chart:

在此处输入图片说明

I have simplified the code so I don't use my actual data, and I am using the following objects:

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)

What I would like is to have the axes to cross at (0,6), and horizontal tick points to increment in multiples of 5.

Any help with sorting this would be great!

Do either of the following get at what you're after?

Approach 1: Regular axes (xaxs='r'), with a box?

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()

Approach 2: Or tighter axes (xaxs='i'), but with slightly exaggerated x and y limits and a box?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM