0

readShapeSpatial我希望在 .shp using函数上使用背景颜色。任何人都可以帮助我吗?是否有任何类似的功能(除了readShapePoly:)可用于为 .shp 文件添加背景颜色?

这是我的代码的一部分...

library(raster)
library(maptools)
library(mapdata)
library(maps)
library(scales)

pcontorta <- readShapeSpatial("PER_water_areas_dcw.shp")
pcontorta2 <- readShapeSpatial("BOL_water_areas_dcw.shp")
pcontorta3 <- readShapeSpatial("ECU_water_areas_dcw.shp")
pcontorta4 <- readShapeSpatial("PRY_water_areas_dcw.shp")
pcontorta5 <- readShapeSpatial("PER_adm2.shp")
pcontorta6 <- readShapeSpatial("BOL_adm2.shp")
pcontorta7 <- readShapeSpatial("ECU_adm2.shp")
pcontorta8 <- readShapeSpatial("PRY_adm2.shp")

read.csv("coord.csv") -> data
Data <- data.frame(data[,1:4])

Data[Data$species=="B._nn",] -> primera
Data[Data$species=="B._ghn",] -> segunda
Data[Data$species=="B._bolivianus",] -> tercera
Data[Data$species=="B._brevirostris",] -> cuarta
Data[Data$species=="B._diasphanus",] -> quinta
Data[Data$species=="B._osgoodi",] -> sexta
Data[Data$species=="B._pachacuti",] -> septima
Data[Data$species=="B._phoenicoteru",] -> octava
Data[Data$species=="B._pectinatus",] -> novena
Data[Data$species=="B._peruanus",] -> decima
Data[Data$species=="B._thomasi",] -> once
rownames(Data) <- data[,1]
attach(Data)
na.omit(Data) -> Data
alt <- raster("alt.bil")
extent_all <-extent (-85, -50, -30, 5)
crop(alt, extent_all)->alt
tiff(filename = "Mapa.tiff",res = 800, pointsize = 6, width = 3200, height = 3200, units = "px")

#...
#Continues a little bit...plotting...

box()
dev.off()

感谢,并有一个愉快的一天!

4

1 回答 1

1

一般来说,shp 文件不会有背景,这取决于如何创建绘图的背景颜色。

使用来自的示例?readShapeSpatial

xx <- readShapeSpatial(system.file("shapes/sids.shp", package="maptools")[1],
                   IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))

(1) 在绘图时使用bg

IE

 plot(xx, col = 'red', bg = 'blue')

(2) 将绘图背景设置为"transparent"并在输出设备中定义

tiff(filename = "Mapa.png",bg = 'green')
plot(xx, bg = 'transparent', col = 'white')
dev.off()
# which gives (converting to `png` to allow this to be uploaded to SO)

在此处输入图像描述

于 2013-07-24T01:41:22.897 回答