Skip to content

Zoom In/Out maps library

7 messages · reichm@@j m@iii@g oii sbcgiob@i@@et, rmendelss gmail, Roy Mendelssohn - NOAA Federal

#
R Help

Anyone know if I can add a zoom In/Out function to the maps available via the "maps" library? Or do I need to use a different mapping library?

world.map <- map_data("world")

ggplot(data = world.map) +
  geom_polygon(mapping = aes(x=long, y=lat, group=group))

Jeff
#
world.map <- maps::map("world", plot = FALSE, fill = TRUE)
p <- sf:: st_as_sf(world.map, coords = c('x', 'y'))
map view::map view(p)

HTH,

-Roy
#
world.map <- maps::map("world", plot = FALSE, fill = TRUE)
p <- sf:: st_as_sf(world.map, coords = c('x', 'y'))
map view::map view(p)


HTH,

-Roy
**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
#
Or if you prefer plotly:

world.map <- maps::map("world", plot = FALSE, fill = TRUE)
p <- sf:: st_as_sf(world.map, coords = c('x', 'y'))
plotly::ggplotly(
ggplot2::ggplot(data = p) + ggplot2::geom_sf()
)
**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
#
Roy

Thank you - that's helpful.  Going to have to read up on sf and mapview
library. Those are new ones.  Then to add a point feature layer (lat/long)
where would I insert that?

Library(maps)
Library(sf) # simple features
Library(mapview)

world.map <- maps::map("world", plot = FALSE, fill = TRUE) 
p <- sf::st_as_sf(world.map, coords = c('x', 'y')) 
mapview::mapview(p, legend=FALSE)



-----Original Message-----
From: rmendelss gmail <rmendelss at gmail.com> 
Sent: Wednesday, March 6, 2019 4:11 PM
To: reichmanj at sbcglobal.net
Cc: R help Mailing list <r-help at r-project.org>
Subject: Re: [R] Zoom In/Out maps library

world.map <- maps::map("world", plot = FALSE, fill = TRUE) p <- sf::
st_as_sf(world.map, coords = c('x', 'y')) map view::map view(p)

HTH,

-Roy
the "maps" library? Or do I need to use a different mapping library?
#
see https://r-spatial.github.io/mapview/index.html

The main thing is the data types that map view supports,  so you must have a raster or an spatial object like an "sf" object.   So points would have to also be an sf object and the two combined  (sf has commands to do this) or perhaps you can do ti directly in mapview,  I haven't played with it much.

The plotly example I sent works with ggplot2,  so if you know how to build up the map in ggplot2 you can try that,  though again as far as I can see plotly for maps needs sf objects.

Mainly sent you the links to get you started.  I haven't played with either much,  just know that they exist and zoom maps.

HTH,

-Roy
**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
#
Also,  I forgot that tmap can do interactive maps, see:

https://geocompr.robinlovelace.net/adv-map.html#interactive-maps

-Roy
**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.