0

I am trying to plot geospatial sea surface temperature correlation data on the world map (only Northern hemisphere). I am using the image function (plot correlation data) along with the map function (plot coastlines). On their own, I get them to work. My problem is I am not able to overlay the map on the image, the map just shows up as a small point at the left corner at the bottom of the plot. The packages I am using are graphics for the image function and maps for the map function.


Generate test data

cor_nao_map = array(data = NA, dim = c(384,96))
for(i in 1:384) {
  cor_nao_map[i, ] = runif(96)  
} 

Plot

image(x = 1:384, y = 1:96, z = cor_nao_map, col = diverge_hcl(100), 
      zlim = c(-0.43,0.43), xlab = "Longitude in °", ylab = "Latitude in °N")  

map('world', projection = "gilbert", add = T)
Community
  • 1
  • 1
  • 2
    I would recommend you to look into [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) . It will make it much easier for others to understand and answer your question. – Hart Radev Nov 08 '19 at 14:23
  • may I ask what is missing or unclear specifically? I am not only new to stackoverflow, but also to R, so I'm kind of having a hard time with this – claradenken Nov 08 '19 at 14:42
  • 1
    Try to write a code sample that would give you a similar error even if you didn't have any variable saved beforehand. Or, to put in simpler words, if I run now the code from your question in my computer, it will not run, because I don't have the data that you do. As a tip, for example, use dput(x), being x the variable you are using, so that we can understand and get the same problem you are having. . – Hart Radev Nov 08 '19 at 14:49
  • @HartRadev I have edited the code, is it more reasonable now? – claradenken Nov 11 '19 at 10:55
  • It has improved, but there's still an error: ```Error in diverge_hcl(100) : could not find function "diverge_hcl" ``` You need to specify the libraries needed to run your code. – Hart Radev Nov 11 '19 at 18:39
  • @Hart Radev True, I think it is from the package "colourvalues". But it is fine now, I got it to work! I had to adjust the longitudes so they go from -180° to 180°. Do I delete this now or leave it? – claradenken Nov 13 '19 at 19:07
  • You can add your solution as an answer to your own question, and in 24 hours (if I remember correctly) you can accept it as the correct one. – Hart Radev Nov 14 '19 at 14:45

1 Answers1

0

I got it to work by adjusting the longitudes so they go from -180° to 180°.