dual y axis plot

I am trying to plot a dual y axis plot using the following code:
plot(dataset1, col="black", ylab="Height (ft)", main = "W7R001")
par(new = TRUE)
points(dataset5, col="red", pch = ".", xlab="", ylab="", axes = FALSE)
axis(side = 4)
mtext(side = 4, "Height (m)").

My issue now is that, on the secondary plot, the label of the secondary y axis lies on the secondary y axis vales. How do I fix or avoid this?A01_2

Hi @Thandohlove

See ?mtext, line arg. I think that's what you're looking for

If I put the line function, it returns an error. Its not working.

Not line function. See ?mtext and read about the line argument.

Otherwise, what error, exactly?

Yes, glad you solved it.

I directed you to the help for base plotting because you used base R in your question. If you use ggplot2 at all, you might be interested to know you can also do the same like this

ggplot(tibble(x = 1:10, y = 1:10), aes(x, y)) +
  geom_point() +
  scale_y_continuous(sec.axis = sec_axis(~. * 0.3,  name = 'Metres')) +
  labs(x = 'X label', y = 'Feet')

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

I had to increase plot margins and shift the label.