Articles

Affichage des articles du août, 2016

Common legend for two plots

Image
With layout Impossible to put a common title correctly layout(mat=matrix(c(3, 1, 4, 2), ncol=2), heights = c(10, 90)) par(mar=c(4, 4, 1, 1)+0.4) plot(x = 1, y = 1, ylim = c(0, 2), xlim = c(0, 2), bty="n") points(x = 2, y = 2, col = "red") plot(x = 2, y = 2, ylim = c(0, 2), xlim = c(0, 2), bty="n") points(x = 1, y = 1, col = "red") par(mar=c(0, 0, 0, 0)+0) plot.new() text(x=1, y=0.5, labels = "Common title", cex=2, pos=2) plot.new() text(x=0, y=0.5, labels = "for both graphics", cex=2, pos=4) layout(1) With par(fig=c(x1, x2, y1, y2)) It is more easy to set up exact position of ploting region # restore all par() values to their defaults dev.off() plot.new() par(fig=c(0, 0.5, 0, 0.9)) par(mar=c(4, 4, 1, 1)+0.4) plot(x = 1, y = 1, ylim = c(0, 2), xlim = c(0, 2), bty="n") points(x = 2, y = 2, col = "red") par(fig=c(0.5, 1, 0, 0.9), new = TRUE) par(mar=c(4, 4, 1, 1)+0.4) plot(x

Variable in italic for plot title

Image
Here is an example how to plot a title in italic using a variable. layout(1) i <- "Caretta caretta" plot(1, main=substitute(expr = paste("Species name: ", italic(i)),                          env = list(i=i))) Or simpler: i <- "Caretta caretta" plot(1, main=bquote("Species name: "*italic(.(i))))