Questions tagged [ggplot2]

Use this tag when referring to the R package for high level data visualization and mapping.

Filter by
Sorted by
Tagged with
15
votes
4answers
32k views

Converting osm file to shapefile (or data frame) in R

I was looking for a road shapefile for Australia today. I ended up going to Geofabrik. Open Street Map has data in .osm format. But they do not have one in .shp for Australia. If possible, I want to ...
13
votes
2answers
320 views

How to create a map of Denmark with ggmap

I have installed the following two packages: library(ggmap) library(maps) I have found code online to create a world map (see below). How do I zoom the plot on a country level? For example, Denmark. ...
12
votes
2answers
2k views

Point overplotting on maps in R (e.g. with ggplot2) - how to push points to the side, mark original positions, combine close-by points …?

I've got a database containing languages, their longitudes and latitudes and a feature value (either category 1, category 2 or both - in the plot these are marked red, blue and green respectively). ...
10
votes
2answers
1k views

Help choosing most suitable bivariate choropleth mapping coloring scheme

I am trying to overlay a nominal variable (2 categories - rainfed vs irrigated) in a choropleth map over a numeric variable. In order to highlight the difference in pattern among the two categories, ...
9
votes
1answer
4k views

R fortify causing polygons to tear

I'm am having some trouble plotting my spatial data using ggplot2. The map looks fine when plotted using spplot, so I'm assuming that the tearing occurs at the fortify stage. The code is as follows: ...
7
votes
1answer
9k views

How to create a continuous scale with distinct/custom color and value breaks with ggplot2 map

As stated in the title, I'm trying to create a continuous scale with distinct color and value breaks within the ggplot2 package in R. I'm using some dummy code to illustrate my problem: library(...
6
votes
2answers
954 views

Plot tilted map in R

I would like to plot a tilted map, similar to the image below. I would prefer to do this using ggplot2 but I'm glad if there is a solution using base R. Any ideas on how to do this? Here is a dataset ...
6
votes
1answer
3k views

ggmap: clip a map

I'm using ggmap to grab Washington DC and I have a shapefile that I downloaded from here: library(ggplot2) library(ggmap) library(maptools) dc = get_map(location = 'DC', zoom = 12) nhbds = ...
6
votes
1answer
4k views

Anyway to remove points outlying shape in ggplot2?

I am to map a plot of an area and then plot points over it (given by Easting and Northing). However, I found out that there are certain mistakes in the data entered for Easting and Northing resulting ...
6
votes
1answer
11k views

How to create custom discrete color scheme for polygon attributes in ggplot2?

Back again with more questions. :) Data: Zipped ea.ml1 shapefile can be found here, and the country outline can be downloaded here at the GADM site. I've been using the Ethiopia ESRI shapefile. As ...
6
votes
1answer
3k views

How to create a crisp topographical/terrain map with ggplot2?

I am trying to produce a high quality vector based map (in greyshades) in order to report locations. I tried this by getting maps from GADM and SRTM to make a raster as a base for plotting in ...
6
votes
1answer
1k views

Plotting data without geographical coordinates besides the main map in ggplot2

I am trying to plot some data as a bubble chart on the world map using ggplot2 package in R. I am able to proceed as follows. # Load necessay packages library(ggplot2) library(rworldmap) library(...
6
votes
1answer
3k views

Loading a png image as a map with ggplot2/ggmap

I am trying to find a workaround for ggmap's missing support of world maps (i.e. you can't create any maps that show latitudes > 80°, due to idiosyncrasies in the mapproj package). To a limited extend ...
6
votes
0answers
2k views

How to prevent cross-world lines in ggplot world map?

I'm having issues displaying 'great circles' paths and polygons in ggmap, an extension of ggplot2. Please enter the following code to replicate my issues: https://gist.github.com/Robinlovelace/...
6
votes
0answers
1k views

Using stat_density2d with coord_map in ggplot2 [closed]

In my example I am plotting a shapefile for all England & Wales, however I'm interested in the greater London area. If I allow ggplot to simply default and display the entire shapefile then the ...
6
votes
2answers
1k views

Create a 3D topographic map with locations marked on the map using R

I am currently trying to create an interactive 3D surface plot using plotly in R. My dataset includes a matrix of Latitude and Longitude and I have a DEM for the region I would like to make this ...
5
votes
1answer
904 views

Creating an sf object from the maps package

I am trying to use data from the maps package in an sf workflow. I'm not sure if I have the operation correct (see below). It seems to work until state 20 (massachusetts). What am I doing wrong? Maybe ...
5
votes
1answer
2k views

Geographic Heatmaps with Concentric Circles by Distance?

I'm looking to generate a geographic heatmap (using 'ggmap') that overlays some dimension (to start, housing prices) over the lat/lon near a city center. Then I want to create circles of equi-distant ...
5
votes
1answer
447 views

Use “facet_wrap” in ggplot2 with QGIS?

I'm using QGIS 2.6.1 and R version 3.2.2. I'm struggling to get the syntax on a R Script for creating plots via QGIS processing to work. My understanding is that R syntax in QGIS Processing is ...
5
votes
1answer
595 views

Plotting islands in ggplot2

I'm trying to plot bodies of water on my map and struggling with islands in ggplot2. I understand the right/left-hand rule for exterior/interior rings but there is still a problem going from island to ...
4
votes
2answers
830 views

Overlaying a polyshape to faceted maps in R with ggplot?

I have managed to create a faceted map from my data following the approach proposed here http://spatial.ly/2013/12/introduction-spatial-data-ggplot2/ with the following code: ggplot(data = plot.data,...
4
votes
1answer
766 views

ggplot2 fills holes in polygons

I have a shapefile composed of polygons (sample here), many of which have holes in them. I cleaned the polygon layer in GRASS. After cleaning, QGIS's 'Check Geometry Validity' tool returned no errors. ...
4
votes
1answer
465 views

Projection mismatch when plotting precipitation with ggplot

I'm trying to plot accumulated precipitation in Brazil for a given period, see code below: Load packages library(raincpc) library(SDMTools) library(raster) library(ggplot2) library(rgdal) library(...
4
votes
2answers
1k views

How can I create a choropleth from the 2010 census ZCTA shapefile using R and ggplot2?

I have created state and county choropleths in R using ggplot2. The method I have used for this came from Winston Chang's "R Graphics Cookbook". For those choropleths the map was already represented ...
4
votes
1answer
932 views

R: How can I create a polygon from several polygons and a line?

I have some spatial objects that I want to combine, namely three polygons and a line. The ultimate goal is to create a polygon that I can overlay on an area of a map of administrative divisions of the ...
4
votes
1answer
703 views

How to join data from NHGIS to make choropleth maps in R/ggplot2?

I have downloaded shapefiles of county/state boundaries and census data keyed to those shapefiles from the NHGIS. Both the shapefiles and the census data have a GISJOIN column to be used for merging ...
4
votes
0answers
1k views

Fortifying re-projected shapefile for ggplot2 in R

I have a shapefile of US county boundaries which I got from the NHGIS. I can load the file using the rgdal package and see information about it: library(rgdal) shp_1860 <- readOGR("shp", "...
3
votes
1answer
10k views

Why is my stacked area graph in ggplot2 returned as stacked lines? [closed]

I'm having a bit of a problem creating my stacked area chart in ggplot2 in R, for some reason it is returning as a stacked line; e.g. data: library(ggplot2) Sector <- rep(c("S01","S02","S03","...
3
votes
2answers
1k views

How to use ggplot with Processing in QGIS 2.0?

I'm trying to use R scripts within QGIS thanks to Processing. There are some example scripts available and I achieved to plots different columns of the attribute table (with the plot built-in package)....
3
votes
1answer
185 views

fit two sf polygons seamlessly

Copied from my SO question The problem Suppose we have two shapefiles that should border seamlessly. Only, they don't. Is there a way to force them to stick to one another without gaps? The ...
3
votes
2answers
4k views

How to plot gridded map from lat-lon and fill values in R?

I want to plot a spatial map in which each pixel is of 0.25 degree spatial resolution in R. For this I have fill values at 0.25 degree grid spacing. Below is the data ----------------------- ...
3
votes
1answer
229 views

R error fortifying dataframe from shapefile

From a set of 420 files (monthly) containing three columns (longitude, latitude, cluster) I have extracted shapefiles defined by cluster value. To do this I have read some posts in StackOverflow and ...
3
votes
1answer
562 views

Tearing of polygons using ggmap and readOGR

I'm trying to incorporate a shapefile of US states with ggmap and keep getting "tearing" of my polygons. I tried changing group=id to group=group which helped, but didn't seem to resolve the boundary....
3
votes
1answer
688 views

plotting a SpatialPolygons object using lines() without lines connecting separate polygons

This is almost an extension of a question asked on stackoverflow (https://stackoverflow.com/questions/12196440/extract-feature-coordinates-from-spatialpolygons-and-other-sp-classes), so I'll use the ...
3
votes
1answer
2k views

R/ggplot2 adding an additional line/polygon to a choropleth map

I have a choropleth map that represents the number of states being affected by a storm event. This is shown in the image below. I want to lay a transparent line or polygon over these states to ...
3
votes
1answer
81 views

Chaotic geo image in R

I am working with qmap (R package ggmap) and when I enter the following code: qmap("Rotterdam", maptype = "terrain", zoom = 13) + geom_polygon(aes(x = long, y = lat, group = group, fill = ...
3
votes
1answer
3k views

Layer map plots on top of one another in R/ggplot2

I'm making a choropleth map in R/ggplot2. I have the colored part working just fine. This code p <- ggplot() + geom_map(data=c_1860, aes(map_id = GISJOIN, fill = AHL002), ...
3
votes
1answer
786 views

Ggplot2 map with colored background and coord_map()

I'm trying to plot some cities stored in my rda file naobrazokSR.rda on a map from GADM while having a background of the map in color #2C3E4F. Without using the coord_map() this works as intended but ...
3
votes
1answer
275 views

How to measure the area of a hexagonal bin generated using ggplot2?

I've generated a number of plots using the geom_hex and stat_summary_hex functions in ggplot2, and I've adjusted the number of bins until the plot "looked right." That said, I'd like to know the area ...
3
votes
1answer
2k views

Retain “region” elements for when using fortify() on a SpatialLinesDataFrame

I'm layering multiple plots using ggplot2 to create a map of Alaska that combines school location and the major road network. I've learned that despite being labeled "major roads" there is wide ...
3
votes
1answer
2k views

How do I create a heatmap in ggplot?

I'm using R with ggplot2 to generate maps from shapefiles and from data in SQL Server. I'm trying to get to a stage where I can automate a large chunk of the mapping I do. So far this is working well ...
3
votes
0answers
36 views

smearing in Linux, but not in Windows

I must have a Linux library out of wack since the following image has "smears" on the colors. Is there a better term? On my Windows 7 RStudio it works fine. this image is from a Ubuntu 16.04 LTS ...
2
votes
3answers
1k views

Adding a legend to points in the tmap package

I am trying to create a map with several points (about 20), where each point will be represented by a number, and where a legend will have these numbers and names of my points. Is it possible to do ...
2
votes
2answers
756 views

Plotting a certain range in azimuthal projection using ggplot2

I would like to limit a map to a particular range of values (i.e. northern hemisphere) under an azimuthal or orthographic projection in ggplot2. When I set ylim, I receive an error message that ...
2
votes
1answer
107 views

Binding multiple polygons in R

I have a directory that contains around 700 .shp files. I want to create a map in R that displays all of them. The easiest way i could think to do this was to bind them all together and then use ...
2
votes
1answer
420 views

Convert all rasters in a rasterstack to polygons

I need to convert all rasters in a RasterStack to polygons and give the polygons names according to its respective raster. library(raster) ## r is a single raster rpolygon <- rasterToPolygons(r, ...
2
votes
2answers
6k views

Keep customized colors with geom_polygon()

I have plotted a map of France with customized colors with map(): map(database="france", fill=TRUE, col=color) Results: (don't mind the two errors) and then I want to put this map with a ...
2
votes
2answers
297 views

Same colour palettes for two different maps in ggplot2

I am constructing two ion concentration maps in the UK using ggplot2. The dataset used for mapping are lzn.kriged1 and lzn.kriged2 which basically has the same structure: > str(lzn.kriged1) Formal ...
2
votes
1answer
413 views

Cannot fortify rworldmap's default world map with a region argument

I'm using the default world map from rworldmaps as a background layer for a bunch of plots done with ggplot2. In order to do this I have to "fortify" the object returned by getMap() - this converts ...
2
votes
1answer
827 views

Trouble adding proportional circles on top of symbolized polygon in ggplot2 map

Data: Zipped ea.ml1 shapefile can be found here, and the country outline can be downloaded here at the GADM site. I've been using the Ethiopia ESRI shapefile. Branch locations are here. Per the ...