geom_raster
从 ggplot2使用怎么样?
# Make up some data
set.seed(1)
df <- data.frame( matrix( runif(25) , 5 , 5 ) )
# X1 X2 X3 X4 X5
#1 0.5316382 0.4360309 0.09576886 0.56497254 0.43930824
#2 0.2383700 0.1531009 0.71377161 0.39367645 0.42211072
#3 0.5009796 0.6549886 0.05996069 0.08236798 0.08574704
#4 0.1171437 0.8765644 0.29892712 0.06071803 0.78011966
#5 0.5066046 0.5486397 0.34770099 0.07785835 0.09659246
# Abs difference between columns of dataframe
out <- data.frame( t( apply( df , 1 , function(x) abs( diff( x ) ) ) ) )
# Plot using geom_raster
require( ggplot2 )
require( reshape2 )
out.melt <- melt( out )
out.melt$y <- rep( 1:10,times = 9 )
p <- ggplot( out.melt , aes( variable , y , fill = value ) ) + geom_raster()
p