LoginSignup
4
3

More than 5 years have passed since last update.

Rで行列の各数値要素の大小を濃淡で表したい場合

Last updated at Posted at 2013-01-26
library(lattice)

# 10 x 10 の行列を作る

my.nrow = 10
my.ncol = 10
set.seed(123)  # sample() で取得する乱数の種を与える
my.mat <- matrix(data = sample(1:100, my.nrow*my.ncol, replace = TRUE),
                 nrow = my.nrow, 
                 ncol = my.ncol)
xmin <- min(my.mat)
xmax <- max(my.mat)

#Build the plot
pal <- colorRampPalette(c("lightblue", "blue"), space = "rgb")

levelplot(my.mat, main = "10 X 10 Levelplot", xlab = "", ylab = "",
          col.regions = pal(20), cuts = 20, 
          at = seq(from = xmin, to = xmax, by = (xmax-xmin)/20) )

image

4
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3