具有宽范围的热图R
我正在用这张桌子制作一张热图 x 使用此代码具有宽范围的热图R,r,math,heatmap,stat,R,Math,Heatmap,Stat,我正在用这张桌子制作一张热图 x 使用此代码 hv <- heatmap.2(x, col=cm.colors(255), scale="none",trace='none', density="none",lmat=rbind( c(0, 3), c(2,1), c(0,4) ), lhei=c(1.5, 4, 2 ),Rowv = FALSE, Colv = FALSE,dendrogram = "none",margins=c(5,5),xlab="ICOADS ship speed
hv <- heatmap.2(x, col=cm.colors(255), scale="none",trace='none', density="none",lmat=rbind( c(0, 3), c(2,1), c(0,4) ), lhei=c(1.5, 4, 2 ),Rowv = FALSE, Colv = FALSE,dendrogram = "none",margins=c(5,5),xlab="ICOADS ship speed indicator",ylab="ICOADS course indicator")
hv好吧,这里有一种使用ggplot
的方法
library(reshape2) # for melt
library(RColorBrewer) # for brewer.pal(...)
library(ggplot2)
x <- cbind(id=as.numeric(rownames(x)),x)
gg <- melt(x,id="id")
gg$variable <- as.numeric(substr(gg$variable,2,4))
brks <- c(0,10^rep(0:7))
gg$bin <- cut(gg$value,breaks=brks,labels=0:7,include.lowest=T)
ggplot(gg) +
geom_tile(aes(x=factor(id),y=factor(10-variable),fill=bin))+
scale_fill_manual(name="",labels=brks,values=rev(brewer.pal(8,"Spectral")))+
scale_y_discrete(labels=10:0)+
labs(x="",y="")+
theme_bw()+theme(panel.border=element_blank())
library(重塑2)#用于熔化
图书馆(RColorBrewer)#为brewer.pal(…)
图书馆(GG2)
请提供来自dput(x)
的输出。
library(reshape2) # for melt
library(RColorBrewer) # for brewer.pal(...)
library(ggplot2)
x <- cbind(id=as.numeric(rownames(x)),x)
gg <- melt(x,id="id")
gg$variable <- as.numeric(substr(gg$variable,2,4))
brks <- c(0,10^rep(0:7))
gg$bin <- cut(gg$value,breaks=brks,labels=0:7,include.lowest=T)
ggplot(gg) +
geom_tile(aes(x=factor(id),y=factor(10-variable),fill=bin))+
scale_fill_manual(name="",labels=brks,values=rev(brewer.pal(8,"Spectral")))+
scale_y_discrete(labels=10:0)+
labs(x="",y="")+
theme_bw()+theme(panel.border=element_blank())