成都市区划地图可视化 - R语言实现
导入需要的包
library(sp) library(rgdal) library(RColorBrewer) library(classInt) library(maptools)
设置画布大小和边界
par(mar=c(3.1, 3.1, 2.1, 2.1), mfrow=c(1, 1))
读取成都市区划数据
chengdu <- readOGR(dsn='chengdu.shp', layer='chengdu')
设置颜色
colors <- brewer.pal(25, 'Rainbow')
将区域划分为 5 类
class <- classIntervals(chengdu@data$cityname, n=5, style='quantile')
给每个区域分配颜色
col <- findColours(class, colors)
绘制地图
plot(chengdu, col=col, lty='44', lwd=2, border='grey')
添加图例
legend('topright', legend='District', bty='n', fill=attr(col, 'palette'), title='Legend', cex=0.85)
设置坐标轴标签为水平
par(las=1)
添加标题
title(main='成都市')
原文地址: https://www.cveoy.top/t/topic/n9zU 著作权归作者所有。请勿转载和采集!