Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

getMarginWidth

Find the margin width necessary to fit text or a legend next to a plot


Description

Calculates the margin width necessary to fit text or a legend next to a plot.

Usage

getMarginWidth(side=4,labels,is.legend=FALSE)

Arguments

side

Which side of the plot (as in axis).

labels

The text to place next to the plot.

is.legend

Whether the text is in a legend or not.

Details

getMarginWidth reads parameters about the current plot and calculates the left or right (default) margin necessary to fit the strings passed as labels or a legend containing those strings.

Value

A two element list containing the number of margin lines necessary to fit the text or legend and the horizontal center of the margin in user units.

Author(s)

Jim Lemon

Examples

plot(rnorm(10))
 newmarinfo<-getMarginWidth(labels=c("Long label","Even longer label"))
 oldmar<-par("mar")
 par(mar=c(oldmar[1:3],newmarinfo$newmar))
 plot(rnorm(10))
 par(xpd=TRUE)
 text(rep(newmarinfo$marcenter,2),c(0.5,-0.5),
  c("Long label","Even longer label"))
 par(mar=oldmar,xpd=FALSE)

plotrix

Various Plotting Functions

v3.8-1
GPL (>= 2)
Authors
Jim Lemon, Ben Bolker, Sander Oom, Eduardo Klein, Barry Rowlingson, Hadley Wickham, Anupam Tyagi, Olivier Eterradossi, Gabor Grothendieck, Michael Toews, John Kane, Rolf Turner, Carl Witthoft, Julian Stander, Thomas Petzoldt, Remko Duursma, Elisa Biancotto, Ofir Levy, Christophe Dutang, Peter Solymos, Robby Engelmann, Michael Hecker, Felix Steinbeck, Hans Borchers, Henrik Singmann, Ted Toal, Derek Ogle, Darshan Baral, Ulrike Groemping, Bill Venables
Initial release
2021-01-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.