Problem with second axis in plot

Hi Community !

I have a problem with my plot on my second axis. Could you helps me ? I share my code and a picture of my problem :

plot(PLR2$tempshertz, PLR2$diameter_filter , type="l" ,xlab="Seconds" , ylab="Diameter (mm)", main = "PLR2", col="royalblue3")
par(new = TRUE)
plot(PLR2$tempshertz , PLR2$vitesse_diam_filter, axes = FALSE , type = "l" , xaxt = "n", yaxt = "n" , col="red" , xlab = "" , ylab = "")
axis (side = 4, at= PLR2$vitesse_diam_filter, labels = round(PLR2$vitesse_diam_filter, digits =2))
mtext("Speed (mm/sec)" , side = 4 , line = 0.2)
par(mar=c(0,10,10,0))
legend("bottomright", legend=c("Filter diameter", "PLR speed"),
       col=c("royalblue3", "red"), lty=1:1, cex=0.8, title="Legend", bg='grey')

You can see on the right axis I have a lot of lines. I don't know how I can correct that. And when I want change the position of the second axis title (example with "line = 2"), my title is to much on the righ and it disapears.

Anyone have a solution please ?

Yours sincerely,

I find a part of my problem, it need to delete this part in order to have a correct scale on the right :
at= PLR2$vitesse_diam_filter, labels = round(PLR2$vitesse_diam_filter, digits =2)

However, I don't understand why my title axes desapears when I write "line = 3". It's look like the title go out the graph on the right ..

Thank you for your help.

Yours sincerely,

I resolve my problem. You need to use theses functions at the top of your code (before the "plot" function) :

par(mar = c(3, 5, 3, 5))
par(mgp = c(1.6, 0.6, 0))

Yours sincerely,

This topic was automatically closed 7 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.