0

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:

enter image description here

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!

  • Any reason you're using matplot() here rather than base R? With base r, `par()` to set axis intercepts, `plot()` for first series, `points()` for 2nd series, `points()` for 3rd seiries, `axes()` twice for custom axes, `legend()`, then wrap it all in `png()` and you can have a publication ready figure... – joelnNC Feb 07 '19 at 19:27
  • Hi JoelnNC. Thanks for your suggestions, I just chose matplot as it seems to do what's required quite easily. When looking through the help page for par(), I could only find the commands for yaxs and xaxs, which have issues with my charts. Cheers –  Feb 08 '19 at 15:32

1 Answers1

0

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()
joelnNC
  • 459
  • 3
  • 11