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
0 votes
1 answer
11 views

Exporting raster of a map to QGIS from GGplot in R

I used R to make density surface models of whales in GGPLOT. However, l can not work out how to get the model into a raster so i can use it in QGIS. I have been trying as below but the squares of the ...
user avatar
0 votes
1 answer
21 views

Coloring polygons (made with concaveman) in ggplot by column

I'm adapting code for a map made by someone else that uses a package concaveman to generate concave hulls from points. The goal is to plot a number of different polygons in the oceans, and to color-...
user avatar
  • 135
0 votes
0 answers
31 views

How to color lakes and districts in GADM maps?

This might be a trivial question for regular users but I still couldn't find a quick and easy answer. I'm trying to create a map of Uganda in R using data retrieved using the getData("GADM", ...
user avatar
0 votes
1 answer
74 views

Problem with multiple raster plot

This is my code to try plotting three different rasters with ggplot2. However, when I run the code just one raster is displayed. What could the problem be? library(ggplot2) library(dplyr) library(...
user avatar
0 votes
1 answer
164 views

Only a part of the shapefile plotted with ggplot2 in R

I would like to plot shapefiles from the EUFORGEN website (http://www.euforgen.org/) in R (European beech and Scots pine). At first I had problems, because they are files with holes. I was able to ...
user avatar
  • 11
0 votes
0 answers
115 views

How to add polygon in ggplot2 with raster? Polygon is missing from final plot after ggplot

I have a stack of raster's and suppose to find the mean of it. I have done it. Now, I want to add polygon on the mean of raster image that I got. Then, from this raster I wants to save and make it ...
user avatar
  • 318
1 vote
1 answer
113 views

Reprojected data from stars R package takes forever with geom_stars and ggplot2

I'm finding very different plotting results with stars objects after I reproject them and use ggplot2. Consider the following: library(stars) library(ggplot2) system.file("tif/L7_ETMs.tif", ...
user avatar
  • 443
1 vote
1 answer
257 views

Plotting a heatmap of Kriging with coordinate in R

I performed Kriging in R. But I have trouble getting a plot of a colored heatmap showing the resulted interpolated area along with a lon/lat values at the side and on the button. Here is an example, ...
user avatar
1 vote
1 answer
201 views

Limit the x-axis values of a barplot in r

I have a raster that includes the 120 million pixel values 0,1,10,11. I generate a percentage raster. But I want the x-axis to show only the pixel values. a = as.data.frame(diff_raster[[5]]) ggplot(a,...
user avatar
  • 139
0 votes
0 answers
45 views

Loop over dataframes and extract specific values to generate multiple rasters/plots

I would seek help to revise this script. I need to generate multiple plots. For example, the following code works well ggplot and gsave but I would prefer to use raster, and I tried something such as ...
user avatar
  • 39
1 vote
1 answer
97 views

sf package point in polygon

I'm trying to create a simple polygon in sf and select only points within that polygon. What am I doing wrong here? library(sf) library(concaveman) library(ggplot2) foo.df <- data.frame("long&...
user avatar
  • 115
5 votes
1 answer
791 views

Plot two layers (raster and polygon-vector) with ggplot and use the fill-scale* for both layers

I am a little lost. I have a stars object where I would like to use the first attribute and map it to the scale_fill*-function in ggplot. I also have an polygon-object of class sf that has an ...
user avatar
  • 657
0 votes
1 answer
57 views

Eurostat shapefiles plotting with errors

I am trying to plot interactive maps at the NUTS3 level. Initially I was using shapefiles that I constructed myself for the data in QGIS, however, when I tried to use them in R they rendered poorly ...
user avatar
2 votes
1 answer
607 views

Simplify raster size to plot using ggplot geom_raster()

I want to create a map using 'ggplot2'. My data contains shapefile (points data), polygons (European countries). Underneath the vector data, I wanted to place the raster showing extends of forests ...
user avatar
  • 3,226
0 votes
1 answer
316 views

geom_raster showing inverted colors

I am trying to plot a simple single band raster in R using ggplot. The only problem with my plot is that the colors are inverted. How can I fix that? ### For plotting I am using ggplot2 and ggpspatial ...
user avatar
2 votes
1 answer
1k views

Why won't ggplot fill heat map using geom_tile in R?

I am trying to emulate some geom_tile plots I saw in a research paper. The plots were created with simulated data. Below I created a dataframe of "dummy data" using a subset of the actual ...
user avatar
6 votes
1 answer
2k views

Plotting multiple raster stacks with rasterVis::gplot and ggplot2::facet_wrap

I'm trying to ggplot2::facet_wrap a stack of rasters, and then call geom_raster to add more rasters on top of the previously mapped raster stack. Here is a very simple example dataset to re-create ...
user avatar
  • 1,217
1 vote
1 answer
50 views

Why does not the coordinate of the graph match the dataframe?

I drawing the plot of Île-de-France with library(sf) library(ggplot2) df <- read.csv("https://raw.githubusercontent.com/leanhdung1994/Stat_Cons/main/station.csv")[1:3] df2 <- st_as_sf(...
user avatar
  • 113
6 votes
1 answer
5k views

Plotting a raster stack with ggplot2

My aim is to plot a rasterstack as a single image using ggplot2. First, I apply ggplot on a single layer raster using the following code: #Load packages library(raster) library(ggplot2) #Create a ...
user avatar
  • 187
2 votes
1 answer
121 views

Spatial neighbors in ggplot2

I'm trying to make a space plot with ggplot() as indicated here, but I'm having trouble using the nb2lines() function. .shp files are here Error in if (!is.na(projargs) && !nzchar(projargs)) ...
user avatar
  • 123
1 vote
1 answer
320 views

How to perform point to raster operation and plot it with raster of different spatial resolution in R?

I posted a question (please find the link below) regarding raster plots at stackoverflow but could not get the solution. Does anyone here has the solution? https://stackoverflow.com/questions/63209707/...
user avatar
  • 121
1 vote
0 answers
217 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 ...
user avatar
1 vote
1 answer
433 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 ...
user avatar
  • 65
0 votes
1 answer
1k 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 = ...
user avatar
3 votes
1 answer
2k 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 ...
user avatar
0 votes
1 answer
114 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", ...
user avatar
0 votes
2 answers
237 views

Computing Moran's I from a ggplot map using R

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 ...
user avatar
1 vote
1 answer
940 views

Adding elevation point data and lines to topography plot using ggplot2

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, along with points to show the ...
user avatar
  • 13
1 vote
1 answer
603 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 ...
user avatar
  • 35
0 votes
1 answer
486 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 ...
user avatar
3 votes
0 answers
232 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 = "...
user avatar
3 votes
0 answers
91 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 ...
user avatar
  • 153
1 vote
1 answer
596 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 ...
user avatar
  • 657
1 vote
1 answer
814 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 ...
user avatar
1 vote
0 answers
177 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 ...
user avatar
  • 323
2 votes
0 answers
353 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 <-...
user avatar
-1 votes
1 answer
4k 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 ...
user avatar
0 votes
0 answers
30 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 ...
user avatar
2 votes
0 answers
175 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. ...
user avatar
1 vote
1 answer
68 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", ...
user avatar
1 vote
1 answer
276 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 ...
user avatar
  • 95
0 votes
1 answer
560 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 ...
user avatar
  • 1
1 vote
1 answer
67 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 ...
user avatar
-1 votes
1 answer
228 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 ...
user avatar
  • 323
14 votes
2 answers
1k views

Creating map of Denmark using 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. ...
user avatar
  • 323
2 votes
1 answer
371 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 ...
user avatar
  • 95
1 vote
1 answer
751 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 ...
user avatar
2 votes
1 answer
3k 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 ...
user avatar
  • 53
1 vote
1 answer
281 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 ...
user avatar
  • 53
0 votes
1 answer
952 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 ...
user avatar