You can use the function axis
to add an extra axis to the chart and if necessary mtext
to put your label. For example, for a simple chart:
par(mar = c(5, 4, 4, 4) + 0.1)
plot(1:10, ylab = "Eixo Y Esquerdo")
lines(10:1)
axis(4, at = 1:10, labels = seq(10, 100, 10))
mtext("Eixo Y Direito", side = 4, line = 2)
Note that you have to adjust the right margin with par
and that you can put different values of the real position on the axis using the argument labels
.
If the data is from different scales and you prefer not to transform the data from the second axis, you can use the following form:
par(mar = c(5, 4, 2, 4) + 0.1)
plot(1:10, ylab = "Eixo Y Esquerdo")
par(new = TRUE, mar = c(5, 4, 2, 4) + 0.1)
plot(100:1, type = "l", axes = FALSE, xlab = "", ylab = "")
axis(4, at = seq(0, 100, 10), labels = seq(0, 100, 10))
mtext("Eixo Y Direito", side = 4, line = 2)
In this case the argument new = TRUE
of par
makes the graphic area not "clean" when you call the function plot
again. Be aware that from now on the axes will be relative to the values of x
and y
of the second graph.
Several examples and alternatives (with other package functions) are available at similar question by Soen.
the problem is that the second series has a different scale than the first, so I would have to "transform" the data so that they are suitable to be plotted on this second scale. What I need is a way to plot two series on different scales in the same area. The product I want is similar to this image: http://www.chamotlabs.com/ApplicationNotes/HTC/WoodTGA.gif
– Rodrigo Simetti
@Rodrigosimetti I edited the answer with a solution for data at different scales.
– Molx
Perfect, @Molx. Exactly that.
– Rodrigo Simetti