Display only a single state with ggmap - r

Is there a simple way to display only a single state? For example
qmap("Texas", zoom=6)
produces
which obviously also includes all of Oklahoma, most of New Mexico, etc...is there a way to "mask" the surrounding states (and Mexico) to display only Texas?

The short answer is that you need to tell ggmap where Texas is. Typically you'd do that using a shapefile. See e.g.
R: ggmap – Overlay shapefile with filled polygon of regions
Plotting Choropleths from Shapefiles in R with ggmap

Related

R - sf package - is it possible to create a zoomed-in map on top of a larger map with some additional features?

I would like to use the sf package to create a map of Europe and on top of it overlay a smaller, zoomed-in part of Europe. An example of how I would like my map to look like is pasted from Wikipedia here:
So, I know that I could first create a map of Europe, then separately a map of the zoomed-in region, and then probably use ggdraw to overlay them. However, specifically what I am interested in is how to create the red-shaded region which connects two rectangles (see image above). I was hoping that there is some method where this could be done automatically, but if you have any other workarounds, I would be very grateful.

Why is my GIS Shapefile (CRS 4326) not viewed from directly above?

I have loaded two shapefiles into Netlogo. One shapefile's original projection was 4326 (osmdata) and one was originally 28992 (Dutch government data) which was st_transformed(4326) in R. When I load them into Netlogo, it does not display the shapefile directly from above, which it does do from R ggplot
Why is this and how do I get it viewed from above?
It was solved by using gis:set-world-envelope-ds instead of gis:set-world-envelope

How to obtain koppen-geiger climate map for ggmap

I would like to use ggmap to plot several data points on top of a koppen-geiger climate map.
The kopper-geiger data and GIS/KMZ maps can be downloaded here:
http://koeppen-geiger.vu-wien.ac.at/present.htm
I've managed to have a code to plot the points on regular maps, obtained through the get_map function but I fail to use other maps such as koppen-geiger.
Any help will be appreaciated!
Your basic problem is that the map you are attmepting to use is an image file that is not georeferenced. So unless you want to go through the unnecessary and probably time consuming process of georeferencing this image yourself, you will be better taking an alternative approach. There are perhaps a few ways to do this. But, unless you have very few data points to overlay on the map which you can place manually using the lat-long grid of the image, then the least painful method will certainly be to redraw the map yourself using the shapefile.
This is not the right place to give you an introductory lesson on GIS, but the basic steps are to
Download shapefile (which is available at the same website as the image you linked)
Project map to desired coordinate system
Plot map, coloring by climate class
Color the ocean layer
Add labels, legend, and graticule, as desired
Overplot with your own climate data, and legend for these.
If you are unsure how to approach any of these steps, then take an introductory course on GIS, and search the Web for instructional materials. You may find this resource useful.
https://cran.r-project.org/doc/contrib/intro-spatial-rl.pdf

Adding Boundaries to Spatial Polygons Object

I have the following SpatialPolygonsDataFrame.
require(raster)
usa <- getData('GADM', country='USA', level=2)
metro <- subset(usa, NAME_1=="Nebraska" & NAME_2 %in% c("Dodge","Douglas","Sarpy","Washington"))
plot(metro)
I would like to be able to replicate the following map boundaries (defined by the colors):
Does anyone know a good plan of attack? I realize this is a somewhat manual process. I have already downloaded all US Census files that are of a more detailed geography. I was hoping that a more detailed level of geography could be aggregated to answer the above question, but unfortunately the districts do not line up the same.
Is there a R function already out there that would be helpful in assisting this manual process? At the very minimum, I would like to be able to leverage the perimeter of the 4-county area.
Use writeOGR from the rgdal package to create a shapefile of your metro object. Then install QGIS (http://www.qgis.org/), a free and open-source GIS, and load the shapefile as a new layer.
Then you can edit the layer, add new polygons, edit lines etc, then save as a shapefile to read back into R.
Additionally, you may be able to "georeference" your image (by identifying known lat-long points on the image) and load that into QGIS as a raster layer. That makes it easier to digitise your new areas. All you need for that is a few lat-long coordinates of specific points, such as the corners of polygons or line intersections, and then QGIS has a georeferencing plugin that can do it.
I don't think you'll find any R code as suitable for digitising new geometries over an image as good as QGIS.
After half an hour (and twenty years experience, not all of which you'll need) I've got this:
I didn't precisely digitise your new boundaries though, just roughly for speed. That QGIS screen cap shows the five coloured areas under the four metro areas.
Step one was georeferencing. This screengrab shows how the PNG has been georeferenced - the red line is the metro area shapefile drawn with transparency over the PNG after the PNG has been converted to a GeoTIFF by matching control points.
Step two was then using QGIS editing tools to split, join, and create new polygons. Then I just coloured them and added labelling to pretty it up.
I could probably bundle these files all up for you to neaten, but it really doesn't take that long and you'll learn a lot from doing it. Also, this is probably a gis.stackexchange.com question...

Protovis map visualization: US+Canada

I'm trying to make a choropleth map which includes both US states and Canadian provinces on the same map and I'm having some issues dealing with the base map. Protovis comes with a dataset called us_lowres.js but there is no good corresponding Canadian dataset...
I have found this SVG map which I would like to use: http://upload.wikimedia.org/wikipedia/commons/5/55/BlankMap-USA-states-Canada-provinces%2C_HI_closer.svg but I want to color it using Protovis if at all possible.
The question is: how can I use the data in this SVG to create a map that protovis can understand? Protovis has functionality for Geographic scales but this SVG is just in whatever linear coordinate system it was drawn in, not lat/lng.
Any great ideas out there? :)

Resources