#加载必要的库 library(rgdal) library(RColorBrewer) library(classInt) library(maptools) library(ggplot2)

#读取行政区划数据 cityname <- readOGR("path/to/shapefile","chengdu")

#设置颜色和图例 colors <- brewer.pal(25,"RdYlBu") class <- classIntervals(cityname$District, n=25, style="quantile") legend_title <- "District" brks <- class$brks

#绘制地图 ggplot() + geom_polygon(data=cityname, aes(x=long, y=lat, group=group, fill=cut(District, breaks=brks))) + coord_equal() + scale_fill_manual(values=colors, breaks=brks, drop=FALSE) + labs(title="成都市", fill=legend_title) + theme(plot.title=element_text(hjust=0.5), legend.justification=c(1,1), legend.position=c(1,1), legend.title=element_text(size=10), legend.text=element_text(size=8), legend.key.width=unit(0.85,"cm"), axis.text.x=element_text(angle=45, hjust=1)) + guides(fill=guide_legend(title=legend_title, keywidth=0.85, keyheight=0.85, label.position="right", label.theme=element_blank(), nrow=5, byrow=TRUE)) + theme(panel.background=element_rect(fill=NA), panel.border=element_rect(color="darkgrey", size=2, linetype="dashed"), panel.grid.major=element_blank(), panel.grid.minor=element_blank(), axis.line=element_blank(), axis.title=element_blank(), axis.ticks=element_blank(), plot.margin=unit(c(3.1,3.1,2.1,2.1),"cm")

使用r语言为成都市及主城区展示图cityname图名为成都市画框边界下、左、上、右为 31 31 21 21制图使用颜色为彩虹色 25图例在右上角图例缩放为 085图例名为District图例为有外框图例图坐标刻度标签为水平图 添 加 线 型 为 dark grey 线 宽 为 2 线 型 为 点 长 短 线 型

原文地址: https://www.cveoy.top/t/topic/fhLn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录