rnorouzian
rnorouzian

Reputation: 7517

How to rotate 180 degrees an mtext() in R

Apparently, mtext() in R doesn't support the srt parameter whose job is to rotate a piece of text.

I need mtext() to create an axis title on side 4 of my moving plot (i.e., values to be plotted come from a function so they change and so do the plot axes values). I was wondering then, what options do I have to rotate 180 degrees this side 4 axis title?

An example is BELOW:

curve(dnorm(x),-3,3)
mtext("Strength",side=4,srt=180)

Upvotes: 16

Views: 14990

Answers (1)

d.b
d.b

Reputation: 32558

You can use par("usr") to obtain extremes of the plot area and use it to place your text without having to explicitly specify the x and y.

Try

curve(dnorm(x),-3,3)
corners = par("usr") #Gets the four corners of plot area (x1, x2, y1, y2)
par(xpd = TRUE) #Draw outside plot area
text(x = corners[2]+.5, y = mean(corners[3:4]), "Strength", srt = 270)

This way it will always be on the right extreme and vertically in the middle.

Upvotes: 13

Related Questions