如果我想在绘制光栅时提供我自己的图例分类,我可以这样做:
library(raster)
data(volcano)
volcanoR <- raster(volcano)
breakpoints <- c(94,100,120,140,160,180,195)
colors <- c("red","green4","blue","orange","pink","black")
plot(volcanoR,breaks=breakpoints,col=colors)
但是,我的数据是这样的:
set.seed(123)
df <- data.frame(X=seq(1,30,by = 1), Y=seq(1,30,by=1),var1=sample(1:20,30,replace = T),
var2=sample(40:80,30,replace = T),var3=sample(110:120,30,replace = T),
var4 = sample(200:210,30,replace = T))
ras <- rasterFromXYZ(df)
plot(ras) # bad example but gets my point across
如何指定每个图的断点?对于例如对于var1我想指定断点2,4,8,10,15,20。对于var2,45,60,80等。 我这样做了:
plot(ras, breaks = c(2,4,8,10,15,20))
但这为所有四个光栅提供了相同的断点。
答案 0 :(得分:0)
你可以这样做。
library(raster)
library(viridis) # For color schemes
# Create the raster brick
ras <- rasterFromXYZ(df)
# Set 4 figures arranged in 2 rows and 2 columns
par(mfrow = c(2, 2))
# Plot var1
plot(ras$var1, breaks = c(2, 4, 8, 10, 15, 20), col = viridis(5))
# Plot var2
plot(ras$var2, breaks = c(45, 60, 80), col = viridis(2))
# Plot var3
plot(ras$var3, breaks = c(110, 113, 116, 120), col = viridis(3))
# Plot var4
plot(ras$var4, breaks = c(200, 201, 202, 204, 206, 208, 210), col = viridis(6))