Search notes:

R: ggplot2 - heatmap

The following example produces a heat map with ggplot2:
library(ggplot2 );
library(reshape2); # for melt()

data <- data.frame(
          item  = c('ABC',  'DE', 'FGHI', 'JK', 'LMNOP'),
          val_1 = c(   7 ,    9 ,     3 ,   7 ,       2),
          val_2 = c(   1 ,    2 ,     6 ,   3 ,       4),
          val_3 = c(   2 ,    4 ,     9 ,   6 ,       5)
        );


data$tot = data$val_1 + data$val_2 + data$val_3;

data$item <- reorder(data$item, data$tot);

data.molten = melt(data);

ggplot(
   data = data.molten,
   aes(x = variable, y = item ))  +
   geom_tile(aes(fill  = value))  +
   geom_text(aes(label = value))  +
   scale_fill_gradient(low='white', high='red') +
   scale_x_discrete(position = 'top');
Github repository about-r, path: /packages/ggplot2/heatmap.R

See also

Heat maps

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1739271606, '18.116.36.70', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/packages/ggplot2/heatmap(64): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78