Description Usage Arguments Examples
View source: R/scale_to_main.R
Scale a numeric vector design to be used as fig
in par
to express a proportion
of another 'fig' vector. This function enables to easily
map several independent elements, with their own 'fig'
arguments in the unit space (0 to 1 values), within
a common plot area that is also controlled by a 'fig' argument.
1 | scale_to_main(element_fig, main_fig)
|
element_fig |
Numeric, the 'fig' vector delimitating the plot area of a given element, using the unity as a reference. |
main_fig |
Numeric, the 'fig' vector delimitating the common plot area, within which limits the given element should be plot. |
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 38 39 40 41 42 43 44 45 46 47 48 49 | ## Not run:
# graphics device is divided horizontally in two plots
plot1Fig <- c(0, 0.4999, 0, 1)
plot2Fig <- c(0.5099, 1, 0, 1)
# each plot has two independent elements
# placed in a position relatively to a plot area
myElement1Fig <- c(0.85, 1, 0.4, 0.6)
myElement2Fig <- c(0.3, 0.85, 0.7, 0.9)
# put plot fig arguments in a named list for convenience
plotsFigs <- list(plot1 = plot1Fig, plot2 = plot2Fig)
# save the par() configuration
current_par <- par(no.readonly = TRUE)
# iterate over the number of plots
for (i in 1:length(plotsFigs)) {
# set plot area
par(fig = plotsFigs[[i]])
# create main plot
plot(1:10, 1:10)
# create first element
par(fig = scale_to_main(myElement1Fig, plotsFigs[[i]]),
new = T,
mar = c(0, 0, 0, 0))
plot.new()
rect(0, 0, 1, 1)
text(0.5, 0.5, labels = paste("myElement1\n", names(plotsFigs)[i], sep = ""))
# create second element
par(fig = scale_to_main(myElement2Fig, plotsFigs[[i]]),
new = T,
mar = c(0, 0, 0, 0))
plot.new()
rect(0, 0, 1, 1)
text(0.5, 0.5, labels = paste("myElement2\n", names(plotsFigs)[i], sep = ""))
par(current_par)
par(new = T)
}
par(current_par)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.