小编Cha*_*tte的帖子

将树状图添加到 ggplot2 热图中

新 R 用户在这里。我正在尝试向使用 ggplot2 创建的热图添加树状图。我怎样才能做到这一点?我已将代码添加到下面的热图中。

#Mtcars using ggplots and reshape2 
install.packages("ggplot2")
library(ggplot2)
intall.packages("reshape2")
library(reshape2)
data(mtcars)
Cars <- mtcars[c(1:7)] #subset to 6 genres

cor(Cars) # 6x6 cor matrix

#ggplot likes the data 'melted' one value per row
m <-melt(cor(Cars)) 
p <- ggplot(data=m, aes(x=Var1, y=Var2, fill=value)) + geom_tile()
p

#set up a coloring scheme using colorRampPalette
red=rgb(1,0,0); green=rgb(0,1,0); blue=rgb(0,0,1); black=rgb(0,0,0)
RtoBrange<-colorRampPalette(c(red, black ) )
BtoGrange<-colorRampPalette(c(black, green) ) 

p <- p + scale_fill_gradient2(low=RtoBrange(100), mid="black",           high=BtoGrange(100))
p
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助,

夏洛特

r colors dendrogram heatmap

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

colors ×1

dendrogram ×1

heatmap ×1

r ×1