overlay flux footprint over a map - r

I need to overlay a plot over a map (it can be from ggmap or from a file in my pc - not a shapefile).
### Here is the map
library(ggmap)
library(RgoogleMaps)
lat = 49.12978
lon = -122.985
center = c(lat, lon)
bbmap <- get_map(location = c(lon, lat), zoom = 18, maptype = "satellite")
And here! is the data and the code to make the plot that I want to overlay.
library(fields)
image.plot(FFP$x_2d[1,],FFP$y_2d[,1],FFP$fclim_2d)
The main problem is that the plot uses distance to a point to generate a flux density plot, so there are no coordinates (I only have the center coordinates which I used to get the map)
This question is pretty much this! that hasn't been answered, but it seems that the solution is georeferencing the data. However, I don't know how to do that in R. I have tried using the "raster" function to create a 3D raster of the map and the image, using the extent of the map for both, but the plot seems not right because it looks like its rotated.
Ultimately, what I want is to have only the 90% or 80% contour line over the map, not the whole thing.
The final image should look something like this but showing only the most external line, reference image: from this webpage
Hope someone can help!
Thanks!

Related

R "points" function misaligned with map

The points() function will not properly overlay the coordinates onto a map generated with base plot, even though the coordinates all match up.
misaligned map is shown below.
links to 2 simple lists of coordinates:
https://drive.google.com/drive/folders/1m0EgTw_XJ25x5r_IrsSXow-WFwFBLVXm?usp=sharing
(for "main", separator is a semicolon)
Thank you so much for your help, I have been trying to fix this for hours!
I have tried manually specifying the coordinate boundaries but that does not change the issue.
plot(main,col=1,main="",
xlim = c(-124.48,-114.13), ylim = c(32.53,42.01),
)
points(plantcoords)
misaligned plot:
as you can see, the points do not properly line up with the map, even though the range of the coordinates of the points is within the limits of the map.

Recenter world map and shapefiles in R

I'm new to spatial data analyses in R and am stuck on a particular issue. I have overlaid multiple shapefiles on a world map which is centered on the Atlantic Ocean (default centering). All of my layers import fine in this view, but what I would really like to do is re-center everything over the Indo-Pacific. I know how to re-center just the world map, but when I add my shapefiles to the re-centered map they no longer plot properly (they do not wrap and are cut off beyond a certain longitude). I'm assuming I may need to reformat the coordinates specified within each shapefile? Not sure how to resolve this issue.
How everything looks centered over the Atlantic (default):
How I want my map centered, but shapefile extents are cut off/do not wrap:
Here is my code:
map("worldHires") #Used for default centering, works fine with
shapefiles
map("worldHires", wrap=c(0,360), ylim=c(-60,60)) #Used for
reformatted centering, does not work well with shapefiles
shapefile1 <- rgdal::readOGR("shapefile1.shp")
plot(shapefile1, add=TRUE, col=scales::alpha("darkblue", 0.6),
border=FALSE)
shapefile2 <- rgdal::readOGR("shapefile2.shp")
plot(shapefile2, add=TRUE, col=scales::alpha("darkgreen", 0.6),
border=FALSE)
shapefile3 <- rgdal::readOGR("shapefile3.shp")
plot(shapefile3, add=TRUE, col=scales::alpha("darkred", 0.6),
border=FALSE)
map.axes()
Does anyone have any suggestions for fixing this issue? Thanks ahead of time for the help!

R: cropping/zooming a map

I am trying to overlay data on top of a map of Canada, however I can't adjust the zoom as I would like. In the map, I want to be able to see the lines for each province anong with its name (so using map("world", "Canada") isn't desirable)
I have tried altering the zoom, but one is too zoomed out and the other is too zoomed in:
qmap(location = "Canada", zoom = 3)
qmap(location = "Canada", zoom = 4)
I have tried researching on how to crop the image but have been unsuccessful
Thank you!
You can approach this using either the maps and mapsdata packages or continue with ggmap. It just depends on how much detail you want.
library(raster)
library(maps)
library(mapdata)
canada<-getData("GADM",country="CAN",level=1)
plot(canada,xlim=c(-141,-53),ylim=c(40,85),col="gray80",border="gray40",axes=T,las=1)
invisible(text(getSpPPolygonsLabptSlots(canada),labels=as.character(substr(canada$HASC_1,4,5)),
cex=0.75, col="black",font=2))
Using ggmap, you can specify a bounding box when grabbing your spatial data. It still overplots some of the area you are interested in (i.e., plots most of the US). Therefore, reapplying the bounding box values to the ggmap function cuts down the viewable area.
library(ggmap)
lats<-c(40,85)
lons<-c(-141,-53)
bb<-make_bbox(lon=lons,lat=lats,f=0.05)
cda<-get_map(bb,zoom=3,maptype="terrain")
ggmap(cda)+xlim(lons)+ylim(lats)+theme_bw()+labs(x="Longitude",y="Latitude")

Adjust font size in map plots in ggmap

I am trying to plot a number of points on a map of Germany, using the ggmap package, which works great. However, I would like to make some specific changes and do not know how to or if that is at all possible.
To make the maps, I do the following (d is a data frame with longitudes and latitudes):
map <- get_map(location = c(10.25828, 51.11484), zoom = 6, maptype = "terrain")
p <- ggmap(map)
p <- p + scale_x_continuous(limits = c(6.09500,14.95306)) + scale_y_continuous(limits = c(47.39889,55.01250)+c(0,-0.1))
p <- p + xlab("Longitude") + ylab("Latitude")
On that map, I then plot some points. Now, if I set zoom = 6 as above, then the map is very detailed, and lots of city names are printed, along with some white lines for the roads. This makes the map look a bit too "crowded". Here is what the map looks like:
The size of the pdf is also quite large which is not very practical if I want to have multiple maps.
On the other hand, if I set zoom = 5, then the background is less detailed, less roads etc are shown, and the file is smaller. However, the printed font of the city and country names is too large. Here is what it looks like:
So my question is: Can is somehow get a map with details as in zoom = 5, but with the font size of country and city names as in zoom = 6?
Thanks in advance
If you change from get_map to get_googlemap, you can pass a string to the style argument which will get passed to the Google Static Maps API. See the documentation, and a crucial reference.
I don't think you can change text size, but you can simplify roads and remove certain labels like so:
map <- get_googlemap(center = c(10.25828, 51.11484), zoom = 6, maptype = "terrain",
style = 'feature:road|element:all|visibility:simplified&style=feature:administrative.locality|element:labels|visibility:off')
which returns
If you want more labels, it's probably easier to insert them later in R. Adjust as you like.
As far as i know most map services include the labels in the rendered map tiles. I never had this problem in r, but with other map services.
Rendering with smaller labels using a customizable map service should be possible, but ggmap only offers CloudMade maps which might be a bit too expensive.
I would recommend using a different library if possible, maybe the one described at r-bloggers.com they use a custom made map from MapBox
a free service (up to a certain limit) i would recommend.

how to plot a part of map but with limitation arround it

how to plot something like this:
see image here, I didn't have 10 reputation so I can not post image, so paste a image URL here.
http://www.flickr.com/photos/97751721#N07/9089566951
or
http://www.flickr.com/photos/97751721#N07/9091786734
right part of this map is a zoom in map with limitation, that is what I want
if it is use R code or other program language will be more great!
If your have everything as Spatial object you could simply plot with standard plot() and set lim to what ever you like.
require(maptools)
shape <- readShapePoints("shapefile.shp")
plot(shape, xlim=c(minXcoordinate, maxXcoordinate) ylim=c(minYcoordinate, maxYcoordinate))
It is a little unclear to me what exactly you want to do. Do you just want to make a map with a specific set of lon/lat boundaries? Do you need to plot data on top of it? Do you need to control the appearance to make it look like the example you give (with line boundaries & minimal geographic information)?
The ggmap package may get you started on this. The syntax goes like this:
require(ggmap)
# The location argument defines the center of the map
exampleMap <- get_map(location = c(lon = -95, lat = 30), zoom=5)
ggmap(exampleMap)
You can then add data to the map if you like (exactly how is left as an exercise to the motivated student!)

Resources