geom_tile输出是彩色线而不是彩色网格

时间:2017-03-01 12:30:20

标签: r ggplot2 heatmap

我正在尝试使用R中的ggplot2绘制热图。

我想说明运动练习占年龄(50到95岁)和连续5分制的比例。

但是,R不是为每个单元格输出具有特定颜色的网格,而是仅为每一行输出颜色。

如果有人能给我一个小费而不是线条,我会非常感激。

enter image description here这是我使用的脚本:

library(ggplot2)
library(reshape2)

# data
plotpercent0 <- matrix(c(15.25,22.73,20.97,13.43,12.63,13.85,11.46,17.14,14.44,16.09,18.81,21.25,11.9,16.46,14.75,12.99,15.94,19.44,17.86,22.03,25,17.86,30.61,23.68,25,13.89,33.33,21.21,32.35,41.38,46.43,30.3,46.67,23.53,14.29,35.71,27.27,40,42.86,50,50,0,50,100,0,100,15.25,22.73,20.97,13.43,12.63,13.85,11.46,17.14,14.44,16.09,18.81,21.25,11.9,16.46,14.75,12.99,15.94,19.44,17.86,22.03,25,17.86,30.61,23.68,25,13.89,33.33,21.21,32.35,41.38,46.43,30.3,46.67,23.53,14.29,35.71,27.27,40,42.86,50,50,0,50,100,0,100,15.25,22.73,20.97,13.43,12.63,13.85,11.46,17.14,14.44,16.09,18.81,21.25,11.9,16.46,14.75,12.99,15.94,19.44,17.86,22.03,25,17.86,30.61,23.68,25,13.89,33.33,21.21,32.35,41.38,46.43,30.3,46.67,23.53,14.29,35.71,27.27,40,42.86,50,50,0,50,100,0,100,15.25,22.73,20.97,13.43,12.63,13.85,11.46,17.14,14.44,16.09,18.81,21.25,11.9,16.46,14.75,12.99,15.94,19.44,17.86,22.03,25,17.86,30.61,23.68,25,13.89,33.33,21.21,32.35,41.38,46.43,30.3,46.67,23.53,14.29,35.71,27.27,40,42.86,50,50,0,50,100,0,100,15.25,22.73,20.97,13.43,12.63,13.85,11.46,17.14,14.44,16.09,18.81,21.25,11.9,16.46,14.75,12.99,15.94,19.44,17.86,22.03,25,17.86,30.61,23.68,25,13.89,33.33,21.21,32.35,41.38,46.43,30.3,46.67,23.53,14.29,35.71,27.27,40,42.86,50,50,0,50,100,0,100), nrow=5, ncol=46, byrow = T)
plopercent0 = as.numeric (plotpercent0)
colnames(plotpercent0) <- c(50:95) 
rownames(plotpercent0) <- c("CSC1","CSC2","CSC3","CSC4","CSC5")
melted_plotpercent1 <- melt(plotpercent0)
melted_plotpercent1
colnames(melted_plotpercent1) <- c("CSC", "Age", "per")

# plot
output_plotpercent1 <- ggplot(melted_plotpercent1, aes(CSC, Age)) + 
  geom_tile(aes(fill = per), colour = "white") +
  scale_fill_gradient (low = "yellow", high = "red") 
output_plotpercent1

0 个答案:

没有答案