[R] Cannot create a visible Choropleth Legend - GISTools
bgunter.4567 at gmail.com
Tue Mar 7 16:46:51 CET 2017
Did you look at the FAQ?
"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 Tue, Mar 7, 2017 at 1:35 AM, Henry Cann <henri.cann at gmail.com> wrote:
> Apologies Bert, not sure I follow the question?
> The code is sort of pieced together from different thinks I've tried. Due to
> projection issues I've tried various different ways of carrying out a
> spatial join. Most of the code is based around making the join easier e.g by
> recreating unique identifiers in both shape files.
> Have had a look at 7.16 (thanks for suggestion) DOn't believe it applies
> because choro.legend usually outputs straight onto the plot area (I have
> tried this with other code.)
> I tested my same code with a different shapefile and had the same issue so I
> conclude it's probably a by-product of something in my code?
> On 6 March 2017 at 23:14, Bert Gunter <bgunter.4567 at gmail.com> wrote:
>> 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