PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

[FIXED] How to align a map plot and connection plot with a rasterized image in r?

 April 20, 2022     connection, gplots, maps, r, raster     No comments   

Issue

How do I make this map and its points align with my image? [1]: https://i.stack.imgur.com/d6WRc.png

earth <- file.choose()
earth <- readJPEG(earth, native=TRUE)
par(mar=c(360,360,360,360))
grid.raster(earth)
maps:: map(add=TRUE)
points(x=cldrd$longitude, y=cldrd$latitude, col=c("magenta"), cex=(.7), pch=16)    
points(x=outlrd$longitude, y=outlrd$latitude, col=c("black"), cex=(.2), pch=16)
inter <- gcIntermediate(c(10.451526,51.165691), c(-96.8410503,32.8143702), n=100, addStartEnd=TRUE, breakAtDateLine=F)
lines(inter, col=c("#00ffbf"), lwd=.05)

Solution

Read the image and georeference it (it would be preferable to start with georeferenced data, there is plenty to go around)

library(terra)
f <- "https://i.stack.imgur.com/d6WRc.png"
earth <- rast(f)
# eyeballing
ext(earth) <- c(-180, 180, -145, 145)
plotRGB(earth)

The image is so dark, that I figured I should add some lines for orientation

w <- geodata::world(path=".")
lines(w, col="gray")

Now your coordinates

crds <- rbind(c(10.451526,51.165691), c(-96.8410503,32.8143702))
points(crds, pch=20, col="red", cex=2)

library(geosphere)
inter <- gcIntermediate(crds[1,], crds[2,], n=100, addStartEnd=TRUE)
lines(inter, col="#00ffbf", lwd=2)

enter image description here



Answered By - Robert Hijmans
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing