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
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
BTW, I can see why you want a dual y-axis but wy the two plots?
Thanks
system
Closed
May 17, 2021, 7:06pm
3
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.