A caption

A caption

We are going to know how to make the map of Bangladesh.We find it very difficult because the rules and the data of bangladesh map are not availabe on the internet.

We’ll use R version 4.0.2 and RStudio to make the map of Bangladesh.You’ll need to have them installed in your computer.

Download R for Windows

Downlaod RStudio for Windows

First of all we’ll need to install R and RStudio.After installation,we’ll install some R packages which will help us making the desired map.We are gonna use the sf , ggplot2 and gridExtra packages this time.So let’s get started.

install.packages("sf")
install.packages("ggplot2")
install.packages("gridExtra")

To load the packages,we will run the codes below.

library(ggplot2)
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(gridExtra)

After installing and loading the required packages,we can start making our desired map.For this,we need appropriate data with correct geo-loacation which includes proper longitude and lattitude of Bangladesh.

To make this easy,I included the required data here.Download and unzip the data.

Downlaod data # It may take a few minutes.

#Remember the location where you unzip.

First we will need to load the .shp data to our RStudio environment.Where the BGD_adm0.shp data is for sloid map with no fragments,BGD_adm1.shp data is for map with divisional fragments and BGD_adm2.shp is for map with fragments of districts.

Remember the location where you unzipped the data?Then get the location and write the location on the code below.I used my location where I unzipped.

Remember to use slash(/)

bd_data0 <- read_sf("D:/Bangladesh data/BGD_adm0.shp")
bd_data1<- read_sf("D:/Bangladesh data/BGD_adm1.shp")
bd_data2<- read_sf("D:/Bangladesh data/BGD_adm2.shp")

View(bd_data0) # To view the data.

Now we can make our first map using sf and ggplot2.I’ve hidden the legend here.

theme_set(theme_minimal())

map0 <- ggplot(bd_data0)+
  geom_sf(fill="grey",alpha=.9)+labs(title="Solid Map",x="Longitude",y="Lattitude")

map1 <- ggplot(bd_data1)+
  geom_sf(aes(fill=NAME_1))+labs(title="Divisional Fragments",x="Longitude",y="Lattitude")+
  theme(legend.position = "None")

map2 <- ggplot(bd_data2)+
  geom_sf(aes(fill=NAME_1))+labs(title="Fragments of districts",
                 x="Longitude",y="Lattitude")+
  theme(legend.position = "None")

grid.arrange(map0,map1,map2,nrow=1)

Here we go.We’ve just made the map of Bangladesh.Now let we want to show labels of different divisions on the map.For this we’ll need the ggrepel package.

To make labels of different divisions,we would need the specific lat and long for the divisions.Here I did this for you.

library(ggrepel)
lat <- c(rep(22.701002,6),rep(22.356852,11),rep(23.810331,17),
         rep(22.845640,11),rep(24.435316,8),rep(25.765062,8),rep(24.968726,4))
long <- c(rep(90.353455,6),rep(91.783180,11),rep(90.412521,17),
          rep(89.540329,11),rep(88.907295,8),rep(89.309109,8),rep(91.933114,4))
latlong <- data.frame(bd_data2$NAME_1,lat,long)
latn <- unique(lat)
longn <- unique(long)
labels <- unique(bd_data2$NAME_1)
latlongn <- data.frame(latn,longn,labels)
latlongn$labels <-plyr::mapvalues(latlongn$labels,"Chittagong",
                                   "Chattogram") 
ggplot(bd_data1)+
  geom_sf(aes(fill=NAME_1))+labs(title="Divisional Fragments with labels",x="Longitude",y="Lattitude")+
  theme(legend.position = "None")+
  ggrepel::geom_label_repel(data=latlongn,
                            aes(longn,latn,label=labels),alpha=.6,nudge_y = .0001)

So that’it.Thanks for reading with patiently.Happy learning.