# inverting color palete used in a plot in R base

#### gianmarco

##### TS Contributor
Hello,

I am trying to invert the color palette used when plotting a RasterLayer.

See the attached example that can be reproduced with the code below:
C-like:
require(gdistance)
r <- raster(system.file("external/maungawhau.grd", package="gdistance"))
plot(r)
The output is an image representing the terrain elevation data for a volcanic cone near Auckland.
I would like to invert the color palette, so that areas at relative lower elevation will be given green, whereas high-elevation areas will tend toward white.

I cannot find a viable solution on my own.

Thanks
Gm

#### Attachments

• 31.9 KB Views: 0

#### helicon

##### Member
The help page ?plot,Raster,ANY-method states that the default color palette is rev(terrain.colors(255)) so you can invert it by dropping the rev command.

Code:
plot(r, col = terrain.colors(255))

#### gianmarco

##### TS Contributor
Hello helicon,
thanks for the suggestion. Indeed, I overlooked that....thanks for bringing that to my attention.

Cheers
Gm