我必须在不同时刻绘制世界地图上的一个物理变量。所以我要画很多图,就像我要画多少时刻一样。问题是,我的例程默认设置了刻度的结束,这使得读取绘图变得困难。我想要固定比例的结束,以便有一个比例为所有的地块。这是一段我会重用的旧代码
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")}
)我不知道怎么修梯子的末端刻度。我该怎么做呢?
发布于 2012-11-04 02:54:44
如果您只想绘制最大颜色,则只需使用以下命令‘修剪’您传递给绘图例程的value:
df$trimval <- pmin(df$value, 2)
# the range in the example below is roughly -4.5 to 4.5..。并使用该值作为contour.plot的z参数进行绘图。缩进代码和下面的随机"value“参数:
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的颜色绘制的。(我可能会提到,我尝试过使用zlim,但结果并不像我想象的那样好。)
https://stackoverflow.com/questions/13212015
复制相似问题