0

What i am doing: I have two set of data sets one is Shapefile at county level for china and other is csv file which has some value against most of the county. I performed join between these two to create maps in R.

Where i am now: I did everything fine in till mapview function.

What i am looking for now: After joining few county has no value so these are not display at all over map which i understand why ( no issue with this ) but is there any way if i can plot my admin layer county boundary together so at least counties with no data can see ( i mean as a aesthetic point of view)

From below code admin 2 shapefile additional i want to plot with hollow option so no color will appear

Below map showing blank counties after R

This below map is what i am looking for produced through Qgis

M

y code as follows:


library(sf)
library(sp)
library(tidyverse)
library(mapview)
library(leaflet)

admin2 = readOGR("CHN_adm2.shp",verbose = FALSE)
admin2_sf = st_as_sf(admin2)

AllLines_ins <- read_csv("AllLines_Updated.csv")

AllLines_ins$`All Lines`<-as.numeric(AllLines_ins$`All Lines`)



China_Alllines =merge(x = admin2_sf, y = AllLines_ins , by = "NAME_2", all = F)



breaks2 <- c(min(China_Alllines$All.Lines),10000000,50000000,100000000,150000000,200000000,250000000,300000000,350000000,400000000,450000000,500000000,550000000,600000000,650000000,max(China_Alllines$All.Lines))

lable2 <- c("<= 10 Million", "10 - 50 Million", "50 - 100 Million", "100 - 150 Million", "150 - 200 Million" , "200 - 250 Million", " 250 - 300 Million","300 - 350 Million" , "350 - 400 Million" , "400 - 450 Million", "450 - 500 Million" , "500 - 550 Million",
           "550 - 600 Million","600 - 650 Million" ,"> 650 Million" )

#class(ALLlines_Ins_TSI$All.Lines) = "Numeric"
China_Alllines$All.Lines<-as.numeric(China_Alllines$All.Lines)
China_Alllines$TSB <- cut(China_Alllines$All.Lines,  
                           breaks=breaks2, 
                           include.lowest=TRUE, 
                           right=FALSE, 
                           labels=lable2)



mapView(China_Alllines, zcol ="TSI",col.regions=c("#FFFC33","#FFE333","#FFD433","#FFB833","#FF9933","#FF8333",
                                                     "#FF6833","#E3511E","#E3451E","#CB3611","#AF2C0B","#AF210B",
                                                     "#971D0B","#B22222","#971D0B"),
        aspect=1.5,legend=TRUE)
Raj
  • 65
  • 2
  • 6
  • It's your join that removes counties. `merge(..., all = F)` stands for inner join, everything not present in both `x` AND `y` will be removed, this also applies for county polygons. If you replace `all = F` with `all.x = T` in `merge()` you should be all set without adding another layer to mapview. – margusl Jan 31 '23 at 06:28

1 Answers1

0

I added one line at the end of map view as follows:

mapview::mapview(admin2, color = 'black', alpha.regions = 0)
Mhairi McNeill
  • 1,951
  • 11
  • 20
Raj
  • 65
  • 2
  • 6