2

I have 2 contour plots that I want to put into a layout, but the classical par() and layout() are not working for me. Aditionaly, because the plots are in the same scale, I'd like to use a single horizontal label in the top of the layout.

x <- c(0,25,50,75,100)
y <- c(0,10,20)
z1 <- matrix(c(12,12,13,12,5,12,5,5,5,12,5,12,13,14,15), nrow = 5, ncol = 3, byrow = TRUE)
z2 <- matrix(c(1,1,10,1,1,6,7,8,9,10,11,12,13,14,15), nrow = 5, ncol = 3, byrow = TRUE)
A <- matrix(seq(0, 100, by = 25), nrow = 3, ncol = 5, byrow = TRUE) #As x
B <- matrix(seq(0,20, by = 10), nrow = 3, ncol = 5) #As y

layout(matrix(c(1,2), nrow = 2, ncol = 1))

filled.contour(x,y,z1, color=terrain.colors,#
  levels = seq(0,15, by = 1),#
  plot.axes = { axis(1); axis(2); points(A,B);#
    contour(x,y,z1, level=6, label = "6 u", add=TRUE)},#
  key.axes = axis(4, seq(0, 15, by = 3)))

filled.contour(x,y,z2, color=terrain.colors,#
  levels = seq(0,15, by = 1), xlab = "Y label",#
  plot.axes = { axis(1); axis(4);points(A,B);#
    contour(x,y,z2, level=2, label = "2 u", add=TRUE)})

My desired result will be something like

enter image description here

Daniel Valencia C.
  • 2,159
  • 2
  • 19
  • 38
  • 1
    See [several Filled.contour plots on the same device...](https://stat.ethz.ch/pipermail/r-help/2007-February/126130.html): "The problem is that filled.contour uses the layout function internally which messes up any other use of `layout`, `split.screen`, or `mfrow`.". Similar attempt with `mfrow` with links to possible solution: [Multiple filled.contour plots in one graph using with par(mfrow=c())](https://stackoverflow.com/questions/14758391/multiple-filled-contour-plots-in-one-graph-using-with-parmfrow-c) (both easily found when googling "r filled.contour layout"...) – Henrik Nov 22 '17 at 07:33

0 Answers0