maptools

mapping by ggplot2 geom_polygon goes crazy after merging data

房东的猫 提交于 2019-12-06 08:36:22
I am trying to make a grid containing maps of megaregions in the us. I create a SpatialPolygonDataframe from a shape file. then convert it into a data.frame to use ggplot2. as soon as I add the data into the frame, the polygon plots. the file containing SpatialPolygon and the data frame are here: https://drive.google.com/open?id=1kGPZ3CENJbHva0s558vWU24-erbqWUGo the code is as follow: load("./data.rda") prop.test <- proptest.result[which(proptest.result$variable=="Upward N"),] #transforming the data # add to data a new column termed "id" composed of the rownames of data shape@data$id <-

Geographical CRS given to non-conformant data in R

筅森魡賤 提交于 2019-12-06 04:06:42
sorry for bothering you for this, but it is maybe 5 hours I am getting mad on this issue and I don't manage to sort it out. I have a dataset of about 37,000 entries. Each of them has its own Lon and Lat coordinate values. Checking the overall values, they range respectively as follow: Latitude (-54.4871,70.66344) and Longitude (-177.375, 178.4419). This is absolutely reasonable. I created a shapefile with these 37 thousands points using ArcGIS: everything works fine. I need then to process these data using R, the command I used for my code is (maptools package): cells <- readShapeSpatial('RES'

SpatialPolygonDataFrame plotting using ggplot

为君一笑 提交于 2019-12-05 18:29:43
I am having a shape file for the greater London area. I use the readShapePoly function from the maptools package to load it in R as a SpatialPolygonDataFrame . I want to the plot those polygons .. Which I have already done by using the basic of plot function in R. The output looks as shown in this image: Now, I am trying to plot the same shape file using ggplot2 but it doesn't work with me. I am getting some weird lines in the graph as shown blew: The code I used was : london.wards <- readShapePoly("~/TD/london_wards2013/london_wards2013.shp" , proj4string=CRS(projString)) wards.count <- nrow

Plotting a raster behind a shapefile

雨燕双飞 提交于 2019-12-03 13:19:14
问题 How can I plot a "raster" object behind a shapefile object? Both plot fine on their own but the points don't plot over the raster: require(rgdal) require(maptools) require(raster) myproj = "+proj=utm +zone=12 +north +ellps=WGS84 +units=m" shp = readShapeSpatial(fn.shp, proj4string = CRS(myproj)) ras = raster(fn.tif) plot(ras) plot(shp, bg="transparent", add=TRUE) 回答1: Overplotting raster plots with points, lines, and polygons should work just fine, as the following example shows. My best

How to add a column with location-based data to a SpatialPolygonsDataFrame in R?

半城伤御伤魂 提交于 2019-12-02 07:58:57
问题 I have spatial data in R which is loaded as a SpatialPolygonsDataFrame : library(sp) library(tmap) d <- readRDS("data.rds") qtm(d) For the example, I used data for Germany from http://www.gadm.org/download. Below, you see the map plotted by qtm(d) . However, I would like to display my own data. I have locations with longitude and lattitude, and I would like to count the number of points inside the mapped polygons and show those counts as the color of the map below. I have no clue where to

How to add a column with location-based data to a SpatialPolygonsDataFrame in R?

放肆的年华 提交于 2019-12-02 05:22:52
I have spatial data in R which is loaded as a SpatialPolygonsDataFrame : library(sp) library(tmap) d <- readRDS("data.rds") qtm(d) For the example, I used data for Germany from http://www.gadm.org/download . Below, you see the map plotted by qtm(d) . However, I would like to display my own data. I have locations with longitude and lattitude, and I would like to count the number of points inside the mapped polygons and show those counts as the color of the map below. I have no clue where to start. Is there a simple approach that maps locations to the polygons? I'm not very experienced with

R: plotting neighbouring countries using maptools

怎甘沉沦 提交于 2019-12-02 03:14:17
Say I am plotting countries on a world map using maptools, if I were to plot a country, is there a way of plotting the countries that border this country in a different colour? I am using the shapefile wrld_simpl that comes with maptools, so say I plot China: plot(wrld_simpl[wrld_simpl$NAME=='China',], col='red', add=T) is there a way I can get it to plot all the bordering countries to China. I want to be able to do this for lots of different countries so I'd ideally want a general solution, not one specific to just China. How about gTouches or gIntersects in rgeos ? library(rgeos) library

R: ggplot2 with geom_map returns “x and units must have length > 0” error despite values converted to factors

懵懂的女人 提交于 2019-12-01 05:30:06
I'm working on a primitive shiny app that would map some data from the Open Data for Scotland project. I worked out the SPARQL queries that manufacture a data frame resembling the extract provided below dz_label overall.quantiles S010001 8 S010002 9 I have the fortified shapefiles and I'm trying to map them with use of the following code: ggplot() + geom_map(data = dta.simd, aes(map_id = dz_label, fill = as.factor(dta.simd$overall.quantiles)), map = shps.dzs2001) + geom_path(data = shps.dzs2001, aes(x=long, y=lat, group=group), colour="black", size=0.25) The code returns the error Error: 'x'

R: ggplot2 with geom_map returns “x and units must have length > 0” error despite values converted to factors

筅森魡賤 提交于 2019-12-01 04:13:06
问题 I'm working on a primitive shiny app that would map some data from the Open Data for Scotland project. I worked out the SPARQL queries that manufacture a data frame resembling the extract provided below dz_label overall.quantiles S010001 8 S010002 9 I have the fortified shapefiles and I'm trying to map them with use of the following code: ggplot() + geom_map(data = dta.simd, aes(map_id = dz_label, fill = as.factor(dta.simd$overall.quantiles)), map = shps.dzs2001) + geom_path(data = shps

Population-weighted polygon distortion (cartograms)

a 夏天 提交于 2019-11-30 21:21:31
问题 I'm trying to create a map in R that conveys both the shape of underlying geometry (i.e., the physical boundaries) and the relative importance of the object in terms of an associated value. For concreteness, I'd like to focus on reproducing (a version of) the following map* (the shapes , not so much the colors since I can't find the polling data): I also don't want to bother with getting Alaska and Hawaii to appear below the US instead of in their geodesically correct locations. I'm only as