6

I have a data set formed by a 9 points observed in a combination of 2 variables with 3 values each, i.e.

x <- c(0,10,100)
y <- c(0,25,30)
z <- matrix(c(1,2,3,4,5,6,7,8,9), nrow = 3, ncol = 3, byrow = TRUE)

With this data I created a contour plot

filled.contour(x,y,z)

enter image description here

Separately, I created the scatter plot from the points where the data was colected

A <- matrix(c(0,0,0,10,10,10,100,100,100), nrow = 3, ncol = 3) #As x
B <- matrix(c(0,0,0,25,25,25,30,30,30), nrow = 3, ncol = 3, byrow = TRUE) #As y
plot(A,B)

enter image description here

However, when I try to put them together, it doesn't works pretty well. Anyone can help me? How can I put correctly the scatter plot over the contour plot?

x <- c(0,10,100)
y <- c(0,25,30)
z <- matrix(c(1,2,3,4,5,6,7,8,9), nrow = 3, ncol = 3, byrow = TRUE)
A <- matrix(c(0,0,0,10,10,10,100,100,100), nrow = 3, ncol = 3) #As x
B <- matrix(c(0,0,0,25,25,25,30,30,30), nrow = 3, ncol = 3, byrow = TRUE) #As y
filled.contour(x,y,z)
points(A,B)

enter image description here

Daniel Valencia C.
  • 2,159
  • 2
  • 19
  • 38
  • Seems like they are not plotted in the same axes. Y-axis is the same scale, but X-axis is not. – Heikki Nov 21 '17 at 12:29
  • @Heikki How can I solve this? – Daniel Valencia C. Nov 21 '17 at 12:31
  • 2
    See `?filled.contour` : _The output produced by filled.contour is actually a combination of two plots; one is the filled contour and one is the legend. Two separate coordinate systems are set up for these two plots, but they are only used internally – once the function has returned these coordinate systems are lost. If you want to annotate the main contour plot, for example to add points, you can specify graphics commands in the plot.axes argument. See the examples._ – Heikki Nov 21 '17 at 12:38

1 Answers1

3

As comented by @Heikki, I made some modifications:

x <- c(0,10,100)
y <- c(0,25,30)
z <- matrix(c(1,2,3,4,5,6,7,8,9), nrow = 3, ncol = 3, byrow = TRUE)
A <- matrix(c(0,0,0,10,10,10,100,100,100), nrow = 3, ncol = 3) #As x
B <- matrix(c(0,0,0,25,25,25,30,30,30), nrow = 3, ncol = 3, byrow = TRUE) #As y
filled.contour(x,y,z,#
  plot.axes = { axis(1); axis(2); points(A,B)}) #<- New

enter image description here

Daniel Valencia C.
  • 2,159
  • 2
  • 19
  • 38