R語言與醫學統計圖形-【17】ggplot2幾何對象之熱圖


ggplot2繪圖系統——heatmap、geom_rect

這里不介紹更常見的pheatmap包。

1.heatmap函數

基礎包。

data=as.matrix(mtcars)
#接受矩陣
heatmap(data)
heatmap(data,scale = 'column')

image.png

heatmap(data,scale = 'column',
        col=terrain.colors(256),
        Colv = NA,
        Rowv = NA)

image.png

2.geom_tile

ggplot2
中,熱圖可看作若干個小矩形組成。其幾何對象就是rect(矩形)或tile(瓦片),兩者效果相同。

mydata <- data.frame(year=2000:2015,lung=runif(16),
                     liver=runif(16),bone=runif(16),
                     luk=runif(16),eso=runif(16),gas=runif(16),
                     eye=runif(16),brain=runif(16),pan=runif(16),
                     kidney=runif(16),breast=runif(16))
mydata2 <- reshape(mydata,varying = list(names(mydata)[-1]),
                   timevar = 'cancer',direction = 'long',
                   times = names(mydata)[-1])
ggplot(mydata2,aes(x=year,y=cancer))+
  geom_tile(aes(fill=lung))+ #瓦片圖
  coord_polar(theta = 'y',start = 0.25)+ #極坐標轉換
  scale_fill_gradient(low = 'white',high = 'red')+
  guides(fill=guide_colorbar(title = '腫瘤發病率'))

image.png


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM