[R] Cannot create a visible Choropleth Legend - GISTools
Bert Gunter
bgunter.4567 at gmail.com
Mon Mar 6 23:14:19 CET 2017
Perhaps FAQ 7.16 ? (Are you sourcing the code?)
-- Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Mar 6, 2017 at 11:54 AM, Henry Cann <henri.cann at gmail.com> wrote:
> I have combined two layers to create a shapefile which I am colouring using
> the Choropleth function in GISTools. The problem I am having is that
> despite having no other problems with my code including with the actual
> mapping of the choropleth itself, nothing I can do, using choro.legend,
> actually appears. I have checked I am plotting in the right pace using
> locator().
>
> My code is below. I have also attached my data and link to shapefile and
> attached my data.
> Many thanks in advance.
> Henry
> https://borders.ukdataservice.ac.uk/ukborders/easy_download/prebuilt/shape/infuse_dist_lyr_2011.zip
>
> require(rgdal)
> require(sp)
> library(plyr)
> library(dplyr)
> library(RColorBrewer)
> MyDataFile2 <- read.csv("reduced1.csv")
> class(MyDataFile2)
> coordinates(MyDataFile2)<-~X+Y
> class(MyDataFile2)
> writeOGR(MyDataFile2, "Folder", "File9", driver = "ESRI Shapefile")
> Redefined2 <- readOGR(dsn="Folder", layer = "File9")
> proj4string(Redefined2) <- CRS("+init=epsg:4326") # WGS 84
> MyMap <-readOGR(".","infuse_dist_lyr_2011")
> proj4string(MyMap)
> MyMapb <- spTransform(MyMap, proj4string(Redefined2))
> MyMapb at data <- mutate(MyMapb at data, id_poly =
> as.numeric(rownames(MyMapb at data)))
> Redefined2 at data <- mutate(Redefined2 at data, id_la =
> as.numeric(rownames(Redefined2 at data)))
> New <- over(Redefined2, MyMapb)
> New <- mutate(New, id_la = as.numeric(rownames(New)))
> New <- left_join(Redefined2 at data, New, by = c("id_la" = "id_la"))
> New2 <- New %>% group_by(id_poly) %>%
> dplyr::summarise(avgBrit = mean(Brtshns), SumBrit = sum(Brtshns),
> nBrit = n()) %>%
> arrange(id_poly)
> MyMapb at data <- left_join(MyMapb at data, New2, by = c("id_poly" = "id_poly"))
> View(MyMapb)
> shape2 <- MyMapb[!is.na(MyMapb at data$avgBrit),]
>
> myshading = auto.shading(shape2$avgBrit, n=7,
> cols=brewer.pal(7, "Spectral"))
> choropleth(shape2, shape2$avgBrit,shading=myshading)
> choro.legend(48.4,-5.79, myshading,fmt="%4.1f",cex=0.8)
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list