- Hands-On Geospatial Analysis with R and QGIS
- Shammunul Islam
- 263字
- 2021-06-10 18:44:29
Plotting quantitative and qualitative data on a map
We can plot quantitative values using the choropleth() of the GISTools package. We can generate a choropleth using the following commands:
# plot quantitative data
library(GISTools)
choropleth(map_bd, as.numeric(map_bd$value2))
We can also write a title and design this map further, but we will do these things in upcoming chapters. This gives us a nice little map:

Using spplot(), we can also plot qualitative data. First, we need to convert this qualitative attribute or column of SpatialPolygonsDataFrame to a factor variable and use a suitable color range. We have a shapefile of Dhaka's divisions, which consist of seven districts each whose name is stored in the NAME_3 column, and our goal is to color different districts of Dhaka's divisions. Here we have picked seven colors from the RColorBrewer package as there are seven unique values for the NAME_3 column. Plotting to qualitative data (here the names of the districts) or coloring different districts can be done in the following way:
# Plot qualitative data
#install.packages("RColorBrewer")
library(RColorBrewer)
dhaka_div = readOGR("F:/Hands-on-Geospatial-Analysis-Using-R-and-QGIS/Chapter02/Data","dhaka_div")
# check how many unique elements map_bd$NAME_3 has by writing unique(dhaka_div$NAME_3)
unique(dhaka_div$NAME_3)
# There are 7 unique districts and so pick 7 colors
colors = colorRampPalette(brewer.pal(12, "Set3"))(7)
dhaka_div$NAME_3 = as.factor(as.character(dhaka_div$NAME_3))
spplot(dhaka_div, "NAME_3", main = "Coloring different districts of Dhaka division", col.regions = colors, col = "white")
This gives us the following map with every polygon colored according to its name:

We will be learning easier ways to plot now in the next section.
- 自動控制工程設計入門
- 精通MATLAB神經網絡
- Hands-On Artificial Intelligence on Amazon Web Services
- 大數據專業英語
- 計算機應用基礎·基礎模塊
- Visual C# 2008開發技術實例詳解
- 返璞歸真:UNIX技術內幕
- Data Wrangling with Python
- Windows內核原理與實現
- DevOps:Continuous Delivery,Integration,and Deployment with DevOps
- Implementing Oracle API Platform Cloud Service
- 網站前臺設計綜合實訓
- Photoshop CS4數碼照片處理入門、進階與提高
- 基于Proteus的PIC單片機C語言程序設計與仿真
- 菜鳥起飛電腦組裝·維護與故障排查