首页 文章

R:为ascii网格图设置默认颜色

提问于
浏览
0

我正在使用函数 read.asciigrid 以读取ascii网格格式的瑞士地形文件 .

不幸的是,默认的绘图颜色是红色到黄色,但我希望它是棕色的绿色到白色(如 terrain.colors(n) ) . 我试过everthing:设置 par(col=terrain.colors(n)) ,即使是n = length(myasciifile),这是一个非常高的数字,在read.ascii函数中写"col=" ....

有没有人体验过这个功能? R是否设定了情节的默认颜色?我在帮助/互联网上找不到任何信息 .

这是我的代码:(遗憾的是我无法发布我的数据集,但它可以在这里找到:http://www.toposhop.admin.ch/de/shop/products/height/dhm25200_1

数据看起来像这样:NCOLS 6 NROWS 6 XLLCORNER 479900. YLLCORNER 61900.CELLSIZE 5000. NODATA_VALUE -9999 . 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 3200 3300 3400 3500 3600

topo=read.asciigrid("DHM_5000.asc", as.image = TRUE,
plot.image =TRUE, proj4string = CRS("+proj=somerc 
+lat_0=46.95240555555556 
+lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel 
+towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs"))

提前致谢!!!

1 回答

  • 1

    ?read.asciigrid 帮助页面上显示:

    read.asciigrid returns the grid map read; either as an object of class 
    SpatialGridDataFrame-class or, if as.image is TRUE, as list with components 
    x, y and {z}.
    

    我建议你把你的 topo 列表输入 image 函数 - 它有颜色选项,例如 ?image

    image(x, y, z, zlim, xlim, ylim, col = heat.colors(12),
          add = FALSE, xaxs = "i", yaxs = "i", xlab, ylab,
          breaks, oldstyle = FALSE, useRaster, ...)
    

相关问题