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
1
vote
0answers
5 views

Plotting arrows in a map to show shifts in coordinates or points using ggplot2

Plotting arrows in a map to show shifts in coordinates or points using ggplot2 I have three points in my map (latitudes and longitudes of the points: a, b and c are provided below). I would like to ...
1
vote
1answer
8 views

Stat_density_2d density plot seem to show too high density values for a small dataset

I'm working with a two-column data.frame with the columns containing x and y coordinates (Longitude, Latitude). A simple way to visualize a density map is by using the 'stat_density_2d' function. When ...
0
votes
1answer
22 views

Wrong scale in ggplot2 map

I am trying to create a political map of Morocco with regions, using ggplot2, but the scale seems to be wrong. This is the map: And below is the code I used: library(ggplot2) library(ggspatial) YK = ...
2
votes
1answer
27 views

Axis labels with geom_sf & ggmap

I'm trying to create a map using a basemap pulled in using ggmap (get_stamenmap) with some shapefiles plopped on top (geom_sf). I want to change axis labels! Why's it so difficult! When I only plot ...
0
votes
1answer
13 views

plot_usmap Incorrect Legend Values

I am trying to use plot_usmap to map a data frame with two columns - fips and change2 - where the values for change2 range from -34.7 to 91.5. When I run this code: plot_usmap(regions = "counties", ...
0
votes
2answers
32 views

Computing Moran's I from a ggplot map

In an effort to detect spatial autocorrelation using Moran's I in some variables, I was wondering how I could go about creating a polygonal shapefile from a ggplot-created map. My data lists multiple ...
0
votes
0answers
28 views

Including seas inland waters and rivers on a topographical R plot using ggplot2

I have plotted a elevation map using ggplot2 in R of the Dead Sea and surrounding area. I am quite satisfied with the plot, however the data I have does not define the outline of the inland waters, ...
0
votes
0answers
11 views

Data entry is coming as NA after merging with shapefile on R

Once I merge my data file with the shapefile of states in India, the resulting file shows some data entries as NA. For instance, the merged data value for Arunachal Pradesh is showing up as NA but in ...
0
votes
1answer
35 views

Add elevation point data and lines to topography plot using ggplot2

Hopefully this is a simple query. I have pieced together some code to make a topography plot using elevation data and ggplot2. However, now I would like to overlay onto this plot the country outlines,...
1
vote
1answer
60 views

geom_rect rectangle disappears when used together with coord_sf in R

I am plotting a map with ggplot2 and would like to have a rectangle surrounding it. I have tried to create the rectangle using geom_rect function, but whenever I include coord_sf function in the code ...
0
votes
0answers
31 views

Plotting the third variable in R

I want to plot my trajectories using geom_path, by having the changes of speed (in each trajectory) in colorRampPalette. I have seen such a plot, but I do not know how to make it. Here is my current ...
0
votes
1answer
92 views

Base-R legend for quick plot of sf-objects

I have two sf-objects that are polygons and one that is a layer of points. The attributes (columns) don't really matter for quick visualization purposes. I just want to make a basic legend and give ...
3
votes
0answers
64 views

What is tilde (~) for in R? [closed]

I know this is an almost too simple question. But maybe there is a fast answer. Looking through some code to build a leaflet map in R I found that part of code: mypal = colorNumeric( palette = "...
3
votes
0answers
57 views

Remediating path that crosses international dateline

I'm trying to plot the paths of multiple ships on a world map using R and a series of Lat/Lon points. All is well until the ship crosses the international dateline (-180/180) when the path jumps ...
1
vote
1answer
40 views

ggplot2lend for sf-objects

I wanted to make a simple plot of four sf-objects which don't contain much more than the sfc-column and some postal-code information. The sf-objects have the names level 1-4 and plz. What I would ...
1
vote
1answer
242 views

geom_vline and scale_x_discrete dont fit with each other

I am a newbie here. 1, The aim is to plot a graph about the mean NDVI value during a time period (8 dates were chosen from 2019-05 to 2019-10) of my study site (named RB1). And plot vertical lines to ...
1
vote
0answers
100 views

ggplot with island (“Alaska problem”)

The data for this example can be found here: https://github.com/davidbaniadam/maps The problem is essentially the same with Alaska and mainland USA, i.e. I want the size of Alaska to be correct in ...
2
votes
0answers
101 views

Union anti-meridian “multipolygons” after re-centering world map

My goal is to create a world map (using ggplot2) with a Pacific perspective. I have managed to re-center the map, by following this solution. Code below: # world country layer sppolys <-...
-1
votes
1answer
2k views

Reorder legend in ggplot object [closed]

I met some trouble when dealing with the order of ggplot legend. I plotted three lines in one graph, and I tried to use 'scale_colour_mannual' to change the order as the line from top to bottom, but ...
0
votes
0answers
22 views

Polygon boundary is not properly connected in R

I have two points sets, when plotted using geom_point, they look like: What I want to do is draw a polygon using these two datasets, and I expect to get a ring-shape polygon. However, when I use ...
2
votes
0answers
56 views

Assign different colours to intersection between two polygons and difference area

I am quite new to GIS using R. I have two sets of data, upon which I could create two polygons like this: What I want to do is colour the common area (inner 'circle') and the space between borders. ...
1
vote
1answer
44 views

Splitting an administrative region into given number of parts

I have the following plot. I want to divide the administrative region into given number (say 20) equal parts. library(maps) data(world.cities) Pakistan <- data.frame(map("world", "Pakistan", ...
1
vote
1answer
92 views

Order features in a spatialpolygonsdataframe in ggplot2

I have a spatialpolygonsdataframe with many overlapping features. I want to create a map in which the smaller features are displayed on top of the larger ones so that the small ones aren't fully ...
0
votes
1answer
229 views

Plotting Geographical Grid from Long/Lat Coordinates in R

I have a file of coordinates (Long/Lat) that should enable me to plot a series of 10km grid squares covering the UK. However, for each grid square I have five sets of coordinates by way of plotting ...
1
vote
1answer
35 views

Error in mapping connections with great circles [closed]

I am fairly new to R and to map plotting. I am trying to overlay some network information on a world map. I loaded a shapefile from Natural Earth as a large SpatialPolygonsDataFrame via readOGR. I ...
-1
votes
1answer
115 views

Dealing with Islands with sf objects and the tmap package [closed]

I have the bounderies for the municipalities in the "capital region" of Denmark. The acctual map looks like this: The yellow island is the fourth row in my sf object. I am trying to folllow the ...
14
votes
2answers
728 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. ...
2
votes
1answer
183 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 ...
1
vote
1answer
433 views

Simplifying a SpatialPointsDataFrame in ggplot world

I've been working on a map showing lines running across Europe. Each line is coming from a GPX file, parsed in like so: spdf <- readOGR("data/file.gpx", layer = "track_points") Now, if I plot the ...
1
vote
1answer
1k views

Setting fill to a variable based on data within SpatialPolygonsDataFrame?

I'm currently on the cusp of getting done what I want to get done - but having a slight problem with referring to my data from within R's sp SpatialPolygonDataFrame object. The issue is how ggplot2 ...
1
vote
1answer
162 views

Using R to create a choropleth generated from lat/lon lists - with data generated internally

a friend referred me here as opposed to the regular Stack Overflow site, as this community maybe better able to help! My issue is largely with the syntax and framework of ggmap,ggplot, and the sp ...
0
votes
1answer
387 views

Stacked area graph in ggplot2 is empty [closed]

I am trying to make a stacked area graph in ggplot2: Zooplankton<-read.table("clipboard".header=TRUE) TransZoop Zoop DensZoop 0 Copepoda 0.066 0 Nauplii 0.425 0 Cladocera 0.199 0 ...
1
vote
0answers
154 views

R colored raster from QGIS to ggplot or tmap

I am fairly new in doing GIS work in R, but I thought this would be a nice situation to get my feet wet. Here is the situation: I need to create multiple plots with the same background, the same ...
0
votes
1answer
4k views

How to make customized radar chart in R? [closed]

I am a beginner in R language and trying to make this picture. I tried radar. I tried using radarchart (radarchart(data)) but I do not know how to modify the picture. Here is my data: A B ...
1
vote
0answers
176 views

could not find function “merge_eurostat_geodata”

Just a couple of codes with the same error at the time of merge data: FIRST CODE: library(eurostat) library(dplyr) library(ggplot2) library(stringr) fer <- search_eurostat("fertility") ...
2
votes
1answer
975 views

Overlay shapefile on multiband raster using ggRGB and ggplot2 in R

I am trying to use ggplot2 to map a polygon feature class over a raster brick (created from multiple Landsat band images). I'm able to map the polygons and the raster separately, but when I try to ...
2
votes
2answers
840 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
0answers
202 views

Plotting gam spatial estimates over map?

I have imported Italy map with the following code: library(ggplot2) library(mgcv) library(ggmap) Country <- "Italy" Get_Map_Country <- get_map( location = Country , zoom = 6 ,...
1
vote
1answer
702 views

symbols for different polygon layers in ggplot2

I'm trying to plot the boundary of different spatialPolygonsDataFrames in ggplot2 or in rasterVis gplot(), but I just can't find the way, they tend to overwrite the previous one; this is something ...
3
votes
0answers
38 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 ...
3
votes
1answer
1k 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
289 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 ...
0
votes
2answers
532 views

ggplot2 adding extra polygons

So, I'm working with a dataset of polygons generated at different levels of sensitivity to error from a citizen science project. I have been trying to visualize how my sensitivity threshold changes ...
0
votes
2answers
2k views

raster::plot() plotting raster too small- is there an alternative on ggplot?

I am trying to plot this raster on R. The object is quite big, but when plotting it using the raster::plot() function, I obtain a very tiny image, as attached. The code I use to produce it is the ...
3
votes
1answer
685 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, ...
1
vote
2answers
758 views

Unable to Export Kriging Prediction Map

I have performed Kriging using the autoKrige function, that is part of the automap package in R. I obtained this as my output I have realized that maybe the reason why I can not export the ...
0
votes
1answer
1k views

Problems in producing animation GIF files in R

I am trying to produce a GIF file for my maps in R using gganimate but errors show up. devtools::install_github("dgrtwo/gganimate") library(ggplot2) data(sp6, package = 'aqp') p <- ggplot(sp6, ...
3
votes
2answers
6k 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 ----------------------- ...
1
vote
1answer
151 views

How do I manage to get my swedish letters

I am trying to do the map in ´ggplot2´ in ´R´. I use this function from rgdal package: mapa <- readOGR(dsn=path.expand("C:/~/SWE_adm_shp"),layer="SWE_adm2") than I do: fortify(mapa) ggplot(mapa,...
1
vote
2answers
1k views

How to correctly plot SpatialPolygonDataFrames in ggplot and substract them in R

I have a landuse shapefile (contains data and script) that plots differently in Base and ggplot, the reason for which remains a myster after countless hours of playing with it. I read in both ...