Learn R Programming

magicaxis (version 1.9.4)

magplot: Magically pretty plots

Description

Makes scientific plots based on magaxis axes. Particularly designed for log plotting. Utilises base plot for the most part, but the axis drawing is replaced by a call to the magaxis fuction.

Usage

magplot(x, y, log = "", main = "", side = 1:2, majorn = 5, minorn = 5, tcl = 0.5,
ratio = 0.5, labels = TRUE, unlog = "Auto", mgp = c(2,0.5,0), mtline = 2, xlab = NULL,
ylab = NULL, crunch = TRUE, logpretty = TRUE, prettybase = 10, hersh = FALSE,
family = "sans", frame.plot = TRUE, usepar=FALSE, ...)

Arguments

x
The x coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.
y
The y coordinates of points in the plot, optional if x is an appropriate structure.
log
log axis arguments to be passed to plot. E.g. use 'x', 'y', 'xy' or 'yx' as appropriate. Default '' assumes no logging of any axes.
main
Title for the plot. Default is no title.
side
The side to be used for axis labelling in the same sense as the base axis function (1=bottom, 2=left, 3=top, 4=right). A vector of multiple entries is allowed. By default, bottom and left axes are drawn (i.e. side 1 and 2). If side=FALSE then no sides or
majorn
The target number of major-axis sub-divisions for pretty plotting. If length is 1 and length of side is longer than this value is used for all axes. If length of arguments is longer than 1 then these should tally with the relevant axes in side. Obvious re
minorn
The target number of minor-axis sub-divisions for pretty plotting. If length is 1 and length of side is longer than this value is used for all axes. If length of arguments is longer than 1 then these should tally with the relevant axes in side. Obvious re
tcl
The length of major tick marks as a fraction of the height of a line of text. By default these face into the plot (in common with scientific plotting) with a value of 0.5, rather than the R default of -0.5. It is possible to force magaxis to inherit direc
ratio
Ratio of minor to major tick mark lengths.
labels
Specifies whether major-axis ticks should be labelled for each axis. If length is 1 and length of side is longer than this value is used for all axes. If length of arguments is longer than 1 then these should tally with the relevant axes in side. Default
unlog
Determines if axis labels should be unlogged. If axis is found to be logged in par('usr') then the minor ticks are automatically log spaced, however "unlog" still controls how the labelling is done: either logged form (FALSE) or exponent form (TRUE). If a
mgp
The margin line (in mex units) for the axis title, axis labels and axis line. This has different (i.e. prettier) defaults than R of c(2,0.5,0) rather than c(3,1,0). This pushes the numbers and labels nearer to the plot compared to the defaults. It is poss
mtline
Number of lines separating axis name from axis.
xlab
x axis name.
ylab
y axis name.
crunch
In cases where the scientific text would be written as 1x10^8, should the 1x be removed so it reads 10^8. TRUE by default. If length is 1 and length of side is longer then this value is used for all axes. If length of arguments is longer than 1 then these
logpretty
Should the major-ticks only be located at powers of 10. This changes cases where ticks are placed at 1, 3.1, 10, 31, 100 etc to 1, 10, 100. If length is 1 and length of side is longer then this value is used for all axes. If length of arguments is longer
prettybase
The unit of repitition desired. By default it is 10, implying a pretty plot is one with marks at 10, 20, 30 etc. If you are plotting degrees then it might be prettier to display 90, 180, 270 etc. In which case prettybase should be set to 90. If log=TRUE t
hersh
To determines whether all plot text should be passed using Hershey vector fonts. This applies to the axis labels (which are handled automatically) and the axis names. In the case of axis names the user must be careful to use the correct plot utils escape
family
Specifies the plotting family to be used. Allowed options are 'sans' and 'serif'. Depending on whether hersh is TRUE or FALSE these otions are either applied to the Hershey vector fonts (hersh=TRUE) or the default R Helvetica font (hersh=FALSE). magaxis w
frame.plot
Logical indicating whether a box should be drawn around the plot.
usepar
Logical indicating whether tcl and mgp should be forced to inherit the global par values. This might be preferred when you want to define global plot settings at the start of a script.
...
Further arguments to be passed to base plot.

Value

  • No output. Run for the side effect of producing nice plotting axes.

Details

This is a simple function that just turns off most of the plotting output of base plot, and replaces where possible those present in magaxis.

See Also

magaxis,maglab,magerr,magmap,magrun

Examples

Run this code
x=10^{1:9}
y=1:9
magplot(log10(x),y,unlog='x')

magplot(x,y,log='x')

#Not ideal to have two decades between major labels

magplot(x,y,log='x',majorn=c(10,5))

magplot(x,y,log='xy',majorn=c(10,5,5,5),side=1:4)

#Some astronomy related examples:

temp=cbind(runif(10,8,12),runif(10,0,5))

magplot(temp[,1:2], xlab=expression(M['u0298']), ylab=expression(M['u0298']/Yr), unlog='xy')

Run the code above in your browser using DataLab