我必须在不同时刻在世界地图上绘制一个物理变量。所以我必须制作许多情节,因为我需要绘制多少时刻。问题是我的例程默认设置了比例的结束,这使得绘图的阅读变得困难。我想修复比例的结束,以便为所有图表设置一个比例。这是我将重用的旧代码
require(reshape)
require(mapdata)
require(mapproj)
df <- read.table('/media/Lacie2/dati/hy.dat',head=F)
names(df) <- c("value", "x", "y")#, "t")
dfc <- cast(df[ ,-4], x ~ y)
mm<-as.matrix(dfc,ncol=480,nrow=241)
filled.contour(x=seq(0,360,length.out=480),y=seq(-90,90,length.out=241),mm,
color.palette = colorRampPalette(c("lightblue", "blue","violet", "black")),
xlab = "Longitude (°)", ylab = "Latitude (°)",
plot.axes = {axis(1); axis(2);
map('world2Hires',
xlim = c(0, 360),
ylim = c(-90, 90),
add = T, col = "black")}
)
我不明白如何修复阶梯的endcale。我该怎么办?
答案 0 :(得分:2)
如果您想仅绘制最大颜色,那么只需修剪&#39;您传递给绘图例程的value
:
df$trimval <- pmin(df$value, 2)
# the range in the example below is roughly -4.5 to 4.5
...并使用该值作为contour.plot
的z参数进行绘图。缩进代码和随机&#34;值&#34;以下论点:
require(reshape)
require(mapdata)
require(mapproj)
df <- data.frame(value=rnorm( 480*241), x=seq(0,360,length.out=480),y=seq(-90,90,length.out=241) )
df$trimval <- pmin(df$value, 2)
dfc <- cast(df[-1], x ~ y)
mm<-as.matrix(dfc,ncol=480,nrow=241)
filled.contour(x=seq(0,360,length.out=480),y=seq(-90,90,length.out=241),mm,
color.palette = colorRampPalette(c("lightblue", "blue","violet", "black")),
xlab = "Longitude (°)", ylab = "Latitude (°)",
plot.axes = {axis(1); axis(2);
map('world2Hires',
xlim = c(0, 360),
ylim = c(-90, 90),
add = T, col = "black")}
)
因此,颜色范围最大为2,所有大于2的值都用2的颜色绘制。(我可能会提到我尝试使用zlim,结果并不像我想象的那样。)