Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 带有图例范围和颜色分布的spplot问题_R_Spatial_Shapefile_Sp_Maptools - Fatal编程技术网

R 带有图例范围和颜色分布的spplot问题

R 带有图例范围和颜色分布的spplot问题,r,spatial,shapefile,sp,maptools,R,Spatial,Shapefile,Sp,Maptools,我的绘图和图例的正确颜色范围有问题 这是我使用的代码: data.ch4 <- read.csv2("v42_CH4_1970_TOT.txt",skip = 3,stringsAsFactors = FALSE, header = F) num_data <- data.frame(data.matrix(data.ch4)) library(maptools) library(lattice) library(png) #map loading map1 <- read

我的绘图和图例的正确颜色范围有问题

这是我使用的代码:

data.ch4 <- read.csv2("v42_CH4_1970_TOT.txt",skip = 3,stringsAsFactors = FALSE, header = F)
num_data <- data.frame(data.matrix(data.ch4))

library(maptools)
library(lattice)
library(png)

#map loading
map1 <- readShapePoly("CNTR_2014_03M_SH/Data/CNTR_RG_03M_2014.shp")
coordinates(num_data) <- ~V2+V1  
gridded(num_data) <- TRUE

#plotting
png(file="Map2.png",width=35,height=30,unit="cm", res=200, type = "cairo")

spplot(num_data["V3"], xlim=c(-5,35), ylim=c(35,70),
             sp.layout = list("sp.polygons",map1),contour=F)
dev.off()
但同样,这只是一个虚假的规模,它不会工作


第二个快速问题是:如何在绘制数据的基础上添加国家轮廓?因为现在等高线隐藏在彩色数据下:c

转换为因子的数据为图例提供了规则的间隔。您可以通过
colorkey=list(labels=list(at=…,labels=…)
更改标签及其位置

[已编辑;(我注意到有些值超过500,对不起)]
##将数字转换为因子

num_data@data$cutV3太棒了!这正是我需要的!非常感谢:)还有一件事,是否有可能使刻度颜色从深蓝到黄色再到红色(蓝-黄-红)?我在考虑彩虹模式,但我只能使用绿色、低红色或蓝粉色-red@Karmel;
spplot(…,col.regions=colorRampPalette(c(“蓝色”、“黄色”、“红色”),…)
就是您想要的。
#Fixed breakpoints (?)
at <- c(0e+0, 1.5e-5, 1.0e-4, 1.0e-3, 1.0e-2, 1.0e-1, 1.0e+0, 2.0e+0, 1.0e+1, 1.0e+2, 2.0e+2,5.0e+2)

spplot(num_data["V3"], xlim=c(-5,35), ylim=c(35,70),
             sp.layout = list("sp.polygons",map1),
             contour=F,
             at=at) #right there
spplot(num_data["V3"], xlim=c(-5,35), ylim=c(35,70),
             sp.layout = list("sp.polygons",map1),
             contour=F,at=at,
             colorkey=list(at=seq(0, 400, 30))  #right there 
             )
[Edited; (I noticed that some values are over 500, sorry)]

 ## convert numeric to factor
num_data@data$cutV3 <- cut(num_data@data$V3, breaks = c(at, Inf))   # I modified the breaks

spplot(num_data["cutV3"], xlim=c(-5, 35), ylim=c(35, 70), 
   colorkey = list(height = 1, labels = list(at = seq(0.5, length(at) -0.5), labels = at)),
   sp.layout = list("sp.polygons", map1, first = F), contour = F)  # drawn after main plot