in Education by
I am creating a map in R using leaflet and the labels for my polygons are not lining up with what their value should be. The map is meant to separate just Ontario by FSA (Forward Sortation Area), the geojson includes all the FSAs in Canada. So first I subset just the FSAs for Ontario (Using their first letter as this is how FSAs work). file_path <- "data/regions.geojson" fsa <- geojsonio::geojson_read( x=file_path, what="sp" ) #Get subsets fsa_ont <-subset ( x=fsa, subset= grepl( x=fsa@data$CFSAUID, pattern="^L|^M|^P|^K|^N" ) ) The map is also supposed to highlight each FSA by the number of people from that FSA who are in the data. I create a colour palette based on the count of people by the FSA. The colour palette seems to work based on the labels it ends up giving the polygons. #create a colour palette mypalette <- colorBin(palette=c("#8acb88", "#FF9933", "#990033"), domain= pop$Count, bins=c(1,5,10,15), na.color='white') Next a create the map tiles map <- leaflet::leaflet() %>% leaflet::addProviderTiles(providers$OpenStreetMap) Then I create the text for my label. This was a label to check what was going wrong. It should be showing the FSA pulling from the geojson data, then the FSA it is pulling from my data set, and then the count from the data set. The count and the FSA from my data set match each-other on each label, but they do not match the FSA from the geojson. Neither FSA matches what the real name of the polygon should be. mytext=paste("FSA Ont Data: ", fsa@data$CFSAUID, "FSA Ours:", pop$FSA,"Count: ", pop$Count) This is creating the map with my polygons, seems to work well. map_fsa<- map %>% leaflet::addPolygons( data=fsa_ont, weight=1, opacity=3, color="white", dashArray="3", ## fillColor= ~mypalette(pop$Count), ## fillOpacity=.7, highlight = highlightOptions( weight = 2, color = "#666", dashArray = "", fillOpacity = 4, bringToFront = TRUE ), label= mytext)%>% addLegend("bottomright", pal = mypalette, values = pop$Count, title = "Survey Respondents", opacity = 1) map_fsa Picture of output, and a polygon label Picture of Northern Ontario FSAs This is the output of the code: See how the label not only doesn't match the correct FSA for the region but the geojson and my data do not seem to match either. The colour does seem to be correct. Please give me some guidance! Edit: I've looked up solutions to this and the closet i've found was this question but I cannot seem to make it work for my code. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I fixed the problem! The problem was fsa_ont and pop were mismatching so I was able to merge them and use them as one. I merged them together and stored them in the same data set using the following after subsetting fsa_ont: colnames(pop)[colnames(pop)== "FSA"]<-"CFSAUID" ##make column names the same fsa_all <- merge( fsa_ont@data, pop, by="CFSAUID" ##merge based on their common column ) fsa_ont@data <-fsa_all ## put this merged data set into the map data Then I was able to use my new column in the dataframe fsa_ont@data$Count as the fill variable and everything fell into place map <- leaflet::leaflet() %>% leaflet::addProviderTiles(providers$OpenStreetMap) #create a colour palette with handmade bins mypalette <- colorBin(palette=c("#8acb88", "#FF9933", "#990033"), domain= fsa_ont@data$Count, bins=c(1,5,10,15), na.color='white') mytext=paste("FSA Ont Data: ", fsa_ont@data$CFSAUID, "FSA Ours:", fsa_all$CFSAUID,"Count: ",fsa_ont@data$Count ) ## This 'FSA Ont Data:' and 'FSA Ours' should match #Add the FSA polygons to map with correct colouring map_fsa<- map %>% leaflet::addPolygons( data=fsa_ont, weight=1, opacity=3, color="white", dashArray="3", fillColor= ~mypalette(fsa_ont@data$Count), fillOpacity=.7, highlight = highlightOptions( weight = 2, color = "#666", dashArray = "", fillOpacity = 4, bringToFront = TRUE ), label= ~mytext)%>% addLegend("bottomright", pal = mypalette, values = fsa_ont@data$Count, title = "Survey Respondents", opacity = 1) map_fsa and here is the beautiful map Map working with labels matching! I am still not sure why my original code doesn't work - so I would love any answers on that still.

Related questions

0 votes
    I am working on a Zeppelin notebook with Spark. I am using Leaflet for creating map visualization and also ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    What are custom labels in Salesforce? What is the character limit of custom label?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    __________ function takes various parameters like formula, data, subset, labels, etc. (a) Pears (b) Pairs (c ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    ___________ provides optional labels with the columns and rows. (a) Disnames (b) Dimnames (c) Denmes (d) ... Out of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Axes, axis labels and titles all appear in the ________ of the figure. (a) Directions (b) Margin labels ( ... Networks of R Programming Select the correct answer from above options...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    R objects can have attributes, which are like ________ for the object. (a) metadata (b) features (c) ... Out of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    The R-help and _____ mailing lists have been highly active for over a decade now. (a) R-mail (b) R ... Getting Started of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    How many atomic vector types does R have? (a) 5 (b) 6 (c) 8 (d) 10 This question was addressed ... Getting Started of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    In order to use the R-related functionality in Dundas BI, you must have access to an existing _________ (a ... Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    How many types of data structures does R language have? (a) 2 (b) 3 (c) 5 (d) 8 I have ... Functions and Debugging of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    What are the data types in R on which binary operators can be applied? (a) Scalars (b) Matrices (c) ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    R runs on the ____________ operating system. (a) Linux (b) Windows (c) Ubuntu (d) Any operating system I ... Started of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    What will be the output of log (-5.8) when executed on R console? (a) NAN (b) NA (c) Error ... Functions and Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    ____________ package in R language provides various options for re-randomization and permutations based on statistical ... Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
...