user3236841
user3236841

Reputation: 1258

R: image intensities in the log scale

I have a matrix of probabilities:

x <- matrix(runif(16384), ncol = 128)
image(x)

Now, I would like to have the x (image intensities that are representing the "probabilities") imaged in a log scale.

Any easy suggestions?

Upvotes: 2

Views: 1106

Answers (1)

Jota
Jota

Reputation: 17611

image allows flexibility in setting the breakpoints for coloring using the breaks argument. You can set the color breaks to happen according to a logarithmic scale:

library(viridis) # you don't need this package, I'm just using it for color palette

colorBreaks = 10^(seq(-6, 0, by = 1)) # set color breaks however you want

image(x, breaks = colorBreaks, col = rev(magma(length(colorBreaks) - 1L)))
# use whatever color palette you want.  I used magma() from viridis

There must be one more break than there are colors, which is why I put -1L in col = rev(inferno(length(colorBreaks) - 1L)) enter image description here

Upvotes: 3

Related Questions