utils_plot: Plotting utilities

Description Usage Arguments Value Examples

Description

Set 'neat' graphical parameters suitable for publication, and also label panels on multi-panel figures.

Usage

1
2
3
4
5
6
7
set_par(panels = NULL, CEX = 1, ...)

set_par_mercury(panels = NULL, CEX = 1, ...)

add_label(labels, ...)

add_text(x, y, labels, ...)

Arguments

panels

number of panels (e.g., 1,2,4,9) to plot.

CEX

character expansion factor (default = 1).

...

further arguments passed to par

labels

character vector of text to plot

x

numeric, relative horizontal position

y

numeric, relative vertical position

Value

'set_par' sets graphical parameters, and 'set_par_mercury' does so in a retro style; 'add_label' adds a panel label to upper margin; 'add_text' adds text to the plotting area.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# standard usage
N  <- 99
op <- set_par()
plot(1:N, 1:N+rnorm(N,0,5), ylim=c(0,2*N), xlab='x', ylab='f(x)')
add_text(.1, .9, '+item1')
add_text(.5, .5, '+item2')
par(op)

# is today 1963 ??
x <- runif(99)
y <- sin(6 * pi * x) + rnorm(99, sd=0.1)
## Not run: op <- set_par_mercury()
plot(x, y, cex=0.7, asp=0.25, ylab='f(x)')
add_text(.1, .9, 'SINUSOIDAL', cex=0.9)
add_label('A')

# Project Mercury space missions
#  see: https://www.nature.com/articles/s41526-018-0040-5/tables/3
d <- strsplit(c(
        'MR-3	5/5/1961	0.2577778	0.08444444	0	A.B. Shepard',
        'MR-4	7/21/1961	0.2602778	0.08333333	0	V.I. Grissom',
        'MA-6	2/20/1962	4.923056	4.633333	3	J.H. Glenn',
        'MA-7	5/24/1962	4.934722	4.65	3	M.S. Carpenter',
        'MA-8	10/3/1962	9.219722	8.939444	6	W.M. Schirra',
        'MA-9	5/15/1963	34.33028	34.05833	22	L.G. Cooper'), "\t")
d <- data.frame(do.call(rbind, d), stringsAsFactors=FALSE)
dimnames(d)[[2]] <- c('mission','date','duration',
                      'weightless_hr','orbits','pilot')
d$date <- as.Date(d$date, format="%m/%d/%Y")
## Not run: op <- set_par_mercury(3, cex.axis=0.9, mar=c(4,4,2,1))
plot(d$date, d$orbits, ylim=c(-0.1,25), ylab='Earth orbits',
     xlab='Date', cex=0.7)
plot(d$date, d$duration, ylim=c(-0.1,35),  ylab='Duration (h)',
     xlab='Date', cex=0.7)
plot(d$date, d$weightless_hr, ylim=c(-0.1,35),
     ylab='Duration weightless (h)', xlab='Date', cex=0.7)
mtext('Project Mercury missions', side=3, line=2, cex=1.5, at=-3900)

phytomosaic/ecole documentation built on Jan. 2, 2022, 11:24 p.m.