ggspatial | Enhancing spatial visualization in ggplot2 | Data Visualization library
kandi X-RAY | ggspatial Summary
kandi X-RAY | ggspatial Summary
This package is a framework for interacting with spatial data using ggplot2 as a plotting backend. The package supports sf package objects, sp package objects, and raster package objects, and uses geom_sf() and coord_sf() to do most of the heavy lifting with respect to coordinate transformation.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ggspatial
ggspatial Key Features
ggspatial Examples and Code Snippets
Community Discussions
Trending Discussions on ggspatial
QUESTION
I am using the tmap
package to plot some data on a map. Because of the size of the datasets, you can download the needed ones here (they are public datasets). This code uses the .csv and .shp files in the drive.
I need to move the compass and the scale bar off of the image and below my legends. How can I do this? I haven't seen that the tm_compass
command has an option to move it outside of the image, so is there another way of doing this?
Code:
...ANSWER
Answered 2022-Mar-01 at 20:48QUESTION
What I'm trying to do: plot spatial objects with ggspatial::geom_sf(), using coord_sf() or a combination of ggspatial::layer_spatial() and ggspatial::annotation_spatial() to specify the extent of the of the plot.
This ggplot/ggspatial behavior has been described in several posts, but the "solutions" have been just ad-hoc hacks that do nothing to ensure the issue doesn't re-occur. See: Setting limits for x and y using coord_sf after updating ggplot2 Error when plotting latitude and longitude points on US map in RStudio
This code works just fine:
...ANSWER
Answered 2022-Feb-09 at 12:00I believe this has something to do with the s2 geometry engine behaving in an unexpected fashion.
TL;DR: consider using sf_use_s2(F)
in your code.
Long version:
QUESTION
I have species occurrence records plotted as points on a UK map created with ggplot2. In my csv, there is a column for record year - how do I add a filter so that only records from a specific year/year range are plotted rather than everything? Code is below, happy with map design just want to only plot some records!
...ANSWER
Answered 2021-Dec-16 at 18:43As @GregorThomas mentioned, you want to give ggplot
a subset. You can use filter
on the data in geom_point
.
QUESTION
I am trying to plot species range areas using convex hulls to then calculate the area and create a figure.
There is a well known issue with the 180 degree international dateline that I have been trying to remedy following many examples on SE, e.g:
How to remedy a path that crosses the international dateline with R
This comes close to what I am aiming for but plots in mapview not ggplot2: How to construct/plot convex hulls of polygons from points by factor using sf?
Here is my attempt:
...ANSWER
Answered 2021-Nov-13 at 13:56Please find below a solution to your problem. I used the function st_shift_longitude()
from the package sf
.
Reprex
- Your data (no changes)
QUESTION
I made a map using ggplot2
, ggspatial
and sf
. I used ggspatial
so that I could download open source base maps without relying on Google and needing an API key. The ggspatial
annotation_map_tile
call downloads a set of tiles that provide the base map. I am trying to white out the map outside of the state I am interested in so that the base map only shows within the state.
Here's my code. The dput
for the sf
object is at the bottom. When you run it, you see a map of New Mexico with a black line outlining the state. I'd like to make the map white outside of the state.
ANSWER
Answered 2021-Sep-10 at 08:45You can create a big white mask around NM state, and overlay it over the annotation. It will clip the outside area.
You can get the NM state outline via {tigris}
- highly recommended for any kind US vector data - and create the mask via a combination of sf::st_buffer()
and sf::st_difference()
.
As the mask reaches, by necessity, outside of the plot area you will need to set the x and y limits of your plot by including a coord_sf()
call.
Consider this code:
QUESTION
I have a map of the Northern Hemisphere centered around North America. I would like to draw a red rectangle around the USA (this is part of an inset map) however, I can not seem to get geom_rect
to draw the rectangle. Any ideas?
Code to make map:
...ANSWER
Answered 2021-Jul-06 at 18:39You can add one more layer of geom_sf and mention its own co-ordinates like this:
QUESTION
I am new to using R to make maps. I am trying to make a map of North America (centered on the US) and would like the Great Lakes to be the same color as the ocean color. My current code defaults to having them the same color as the countries/states. Any ideas on how to change their color? Maybe a different base map?
Current code:
...ANSWER
Answered 2021-Jul-02 at 18:17Ok, I did some diggig, turns out that rnaturalearth have the geometries of the lakes of the whole world. ne_download(type = 'lakes')
.
QUESTION
I'm trying to manage large datasets or files (e.g., GeoTIFF) on plain R (via terminal) or RStudio (1.4.1106), but both apps crash every time on Linux (Manjaro, x64, core i7, and 8 GB RAM) for some scripts (especially when a raster data is plotted using ggplot2 to produce a high-quality map, as well as a lmer function with random factors using a csv file with ~3000 rows and 6 columns). Probably the issue refers to memory management since all the memory is consumed. To overcome, I tried two packages to limit/increase the memory size, such as "unix" and "RAppArmor". However, if the memory size is limited, all your available RAM was exhausted and the famous message "cannot allocate a vector..." is shown. On the other hand, if the memory size is increased to high levels, R/RStudio simply crashes. On Windows, the following code works like a charm to increase memory size (only needed to plot a raster into ggplot2):
...ANSWER
Answered 2021-Jun-08 at 02:15With the help of a member from another forum (https://community.rstudio.com/t/out-of-memory-on-r-using-linux-but-not-on-windows/106549), I found the solution. The crash was a result of memory limitation in the swap partition, as speculated earlier. I increased my swap from 2 Gb to 16 Gb and now R/RStudio is able to complete the whole script. It is a quite demanding task since all of my physical memory is exhausted and nearly 15 Gb of the swap is eaten.
QUESTION
I have a problem with plot contour lines using st_as_sf()
in shinyapps.io. I checked all the packages' dependencies and nothing. I know that's in st_as_sf()
because in my all data set, some contour plot works and don't have any geometry problem with my stands_extent
file.
My plot works very well in local Shiny RStudio:
But after publish on shinyapps.io:
My example below and just only with Unique ID
CERROCOROADO_003A the plot work:
ANSWER
Answered 2021-May-19 at 10:26The rgeos
package is missing. Add this to your code.
QUESTION
I'd like to download inside Shiny a georeferenced PDF file (geoPDF) and for this a need some steps like convert the plot in ggplot format to tiff, populate the spatial coordinates, create a geo tiff, and finally my geoPDF. But several steps in downloadHandler()
function in tempdir()
directory results always in the error:
ANSWER
Answered 2021-May-15 at 20:54One thing I notice is that you have no output to file
in download handler. Perhaps your lines:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ggspatial
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page