答案 0 :(得分:2)
这个怎么样:
library(ggplot2)
df<-expand.grid(x=LETTERS,y=1:20)
df$var<-runif(nrow(df))
ggplot(df[sample(1:nrow(df),200),]) + theme_bw() + # subset of df to include blanks
geom_tile(aes(x=x,y=y,fill=var)) + #geom_tile
scale_fill_gradient2(low="green",mid="yellow",high="red",midpoint=0.5) + # add fill gradient
scale_y_discrete(breaks=1:20,labels=1:20) +
coord_fixed(ylim=c(0.5,20.5))
你可以修改scale_fill...
函数来实现你想要的任何布局,基于var(连续或离散)或一些规则。