I'm back again with more R mapping questions! This one is concerning symbolizing points by a certain attribute with graduated/proportional circles.
I've plotted points from the CSV over a shapefile. For the sake of brevity, here's the heavily abridged version of my code:
library(raster) library(rgdal) #set your working directory #read in eth shapefile eth <- readOGR(dsn = "D:/Mapping-R/Ethiopia", layer = "ETH_adm0") #read in total branch location csv branches <- read.csv("Branches_Africa.csv", header = TRUE) #transform branches data frame to spdf for mapping coordinates(branches) <- ~Lon + Lat #plot shapefile with point overlay plot(eth) points(branches$Lon, branches$Lat, col = "blue", pch = 16, cex = .5)
Ideally I would also like to change the colors of each point as well to match the QGIS symbology as closely as possible.
If you look at my full code, you'll notice that I've not used
ggplot to map, so I would prefer the solution not come from that package (or would ggplot make things easier once I've transformed all the data to fit the package?). I tried using
spplot as per this post with:
spplot(branches, "share", col.regions = brewer.pal(9, "Reds"), cuts = 8, scales = list(draw = T))
but the code gave me the following error:
Error in fill.call.groups(args.xyplot, z = z, edge.col = edge.col, colorkey = colorkey, : number of colors smaller than number of factor levels
I also tried to work with
mapCircles from the
rCarto package, but I had no luck there either.
SO, how can I change the symbology of branches$share so that graduated/proportional (and preferably differently colored) circles are displayed instead of just one size/color?