How to increase the size of labels of a legend for a raster and make them bold?

StackOverflow https://stackoverflow.com/questions/20748747

  •  21-09-2022
  •  | 
  •  

문제

I want to plot a raster file.

library(colorRamps) 
library(raster) 

r <- raster(nrows=5, ncols=5, vals=1:25)
plot(r, col =  matlab.like(8))

This produces enter image description here

As you can see, the legend has numbers from 5 to 25. These numbers are not so clear so I want to increase the size of them to be clear and make them bold. Thanks

도움이 되었습니까?

해결책

You can pass axis.args and legend.args as arguments to the legend only function call, as for image.plot in the fields package.

For example, to specify tick positions and labels, It will also accept arguments such as legend.width and legend.shrink.

plot(r, col=topo.colors(100), legend=TRUE, axes=TRUE)
r.range <- c(minValue(r), maxValue(r))
plot(r, legend.only=TRUE, col=topo.colors(100),
     legend.width=1, legend.shrink=0.75,
     axis.args=list(at=seq(r.range[1], r.range[2], 25),
                    labels=seq(r.range[1], r.range[2], 25), 
                    cex.axis=0.6),
     legend.args=list(text='Elevation (m)', side=4, font=2, line=2.5, cex=0.8))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top