Plotting a dual Y axis graph using the same dataframe

I have dataset from 1996/05/01 to 1990/12/31. Between 1996/05/01 and 1973/01/27 the measuring units are in inches and from 1973/01/28 to 1990/12/31 they are in meters. I would like to plot a a graph with dual Y-axis. I have been using the code below but my two graphs are overlaying on top on each other:

This is the code I used:

par(mar = c(5,4,4,4) + 0.3)
plot(df, col="black", pch=".",
     xlim = as.Date(c("1966-05-01", "1973-01-27")))
par(new = TRUE)
plot(df, col= "red", pch= ".",
     axes = FALSE, xlab = "", ylab = "",
     xlim = as.Date(c("1973-01-28", "1990-12-31")))
axis(side = 4, at = pretty(range(df)))
mtext(df, side = 4, line = 3)

Would you plovide som sample data to go with your code?
The function dput(); see ?dput is a handy way to do this or see

BTW, I can see why you want a dual y-axis but wy the two plots?

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.