0
votes

I am using the function read.asciigrid in order to read a swiss topography file in ascii grid format.

Unfortunately, the default plot color is red to yellow, but I would like it to be green to white via brown (as in terrain.colors(n)). I have tried everthing: Set par(col=terrain.colors(n)), even with n=length(myasciifile), which is an enormously high number, write "col=" in the read.ascii-function....

Has anyone experience with that function? Wheres does R set the default color for the plot? I could not find any information in the help/on the internet.

Here's my code: (unfortunately I cannot post my dataset, but it is available here: http://www.toposhop.admin.ch/de/shop/products/height/dhm25200_1)

The data looks schematically like this: 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"))

Thanks in advance!!!

1

1 Answers

1
votes

From the ?read.asciigrid help page it says:

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}.

I suggest you take your topo list and input into the image function -which does have colour options, e.g. ?image:

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