-2

I defined a layout to plot three different plots as:

layout(matrix(c(1,2,3,4),2,2,byrow = TRUE), TRUE)

After that I call the three plots that I want to produce:

image.plot(...)
plot(...)
plot(...)

I will also need to overlay a map (generated with getMap form the rworldmap package ) to the image.plot (in the fields package) with another call like:

newmap <- getMap(resolution = "high")
plot(newmap)  

But because of the layout structure R is interpreting this as the next plot to draw. Is there a way to overlay the map in the same position of image.plot plot and then continue with the other plots?

Thanks

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • 1
    Where does image.plot come from? Can you make a reproducible example? What is 'newmap'? etc. – Spacedman Jul 17 '13 at 12:37
  • @g256, How can we help you if the question is not clear? – Sander Van der Zeeuw Jul 17 '13 at 12:42
  • @Spacedman. I edited the post.Thanks. A reproducible example would be quite tricky in this case. At the end it's just a matter of plotting on the same layout area the underling map. –  Jul 17 '13 at 12:59
  • @Sander Van der Zeeuw even though the example is missing I do think the question is clear. –  Jul 17 '13 at 13:01
  • @g256 can you please give example data? – Sander Van der Zeeuw Jul 17 '13 at 13:27
  • @g256 I agree with Sander. It is not clear. A lack of *any* answers should be a hint that this is true. A quick look at [**how to make a great reproducible example**](http://stackoverflow.com/q/5963269/1478381) will help. – Simon O'Hanlon Jul 17 '13 at 14:36
  • 1
    @g256 changing your `plot(...)` to `plot(1:10)` for example, so the code is something we can cut/paste will get you dozens more people at least trying to duplicate your problem. And where does 'getMap' come from? I tried maptools, failed, gave up. See our problem? – Spacedman Jul 17 '13 at 14:58
  • @Spacedman I added this information to the post. –  Jul 18 '13 at 07:19
  • No you didn't. It still says `plot(...)`. This is important because the plot function does different things when plotting different objects. For example, Greg's solution of `add=TRUE` only works because it is plotting an sp-class object. Try doing `plot(1:10, add=TRUE)` and it will fail. – Spacedman Jul 18 '13 at 08:08
  • @Spacedman I specified that `newmap` has been generated using the `rworldmap` which makes the `add=TRUE` option working. The other two `plot(...)` calls are not a problem and are doing something else (i.e. the other plots in the layout). That's why I left them like that. –  Jul 18 '13 at 08:39

1 Answers1

1

I found a function getMap in the rworldmap package, is that the one that you are using?

If so, it looks like it uses the methods from the sp package to do the plotting, these methods have an add argument that when set to TRUE will add the map to the current plot rather than starting a new plot. So try something like:

image.plot(...)
newmap <- getMap(resolution="high")
plot(newmap, add=TRUE)

and see if that works for you.

And in the future, please specify which packages your are using and give details that will help people help you.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • Thanks for the very useful support and answer. This is working and was exactly the point. I was already aware of the add=TRUE option. Don't really know why I didn't use it. –  Jul 18 '13 at 07:14