私はデータを持っていますが、カラムのtidyrのspread()を使って生成したピボットテーブル(data_wide2)別のスクリプト)。R-ggplotとcorrplotは非常に異なるプロットを作成します(相関マップ/マトリックス)
そして私が生成するため、次のコードを使用する(など、83,35,86)乱雑であるインデックスを占め、他の変数(「開始」)に記載
私のデータのレベルを頼っ相関行列はcorrplot(これはうまくいっていて、ラベル以外の数字に合っていた)。この最初のプロットは、2つの明らかに暗い正方形を示しています。
heatmap <- function(){
data_wide2 <- data_wide
data_wide2$Protein <- reorder(data_wide2$Protein,data_wide2$Start)
data_wide2 <- data_wide2[order(data_wide2$Start),]
pre_matrix <- data_wide2[,8:ncol(data_wide2)]
exp_data <- as.matrix(pre_matrix)
square <- cor(t(exp_data))
square <- (corrplot(square, method = "circle"))
square
return(corrplot(square, method = "circle")) #plot matrix
}
heatmap()
私の最後の数字はplot_grid
の一部でなければならないので、それはggplotオブジェクトでなければなりませんでした。したがって、私は相関マップ/マトリックスに関するチュートリアルを検索しました。私がデータセットに1つを適用したとき、生成されたプロットは以前のものとは何の関係もありませんでした。私の直感は、データが算数順に再編成されたことですが、それを修正する方法はわかりません。
heatmap <- function(){
data_wide2 <- data_wide
data_wide2$Protein <- reorder(data_wide2$Protein,data_wide2$Start)
data_wide2 <- data_wide2[order(data_wide2$Start),]
pre_matrix <- data_wide2[,8:ncol(data_wide2)]
exp_data <- as.matrix(pre_matrix)
square <- melt(cor(t(exp_data)))
plot <- ggplot(square,aes(Var1,Var2,fill=value)) +
geom_tile() +
scale_fill_gradient2(limits=c(-1,1),midpoint=0,low='000000',high='steelblue',space='Lab') +
#scale_x_reverse(lim=c(97,0))
scale_y_reverse(lim=c(97,0)) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, size = 12, hjust = 1))
coord_flip()
plot
print(class(plot))
return(plot)
}
heatmap()
は私が文字に、要因にVAR1を変換しようとしたが、どちらも動作します。
Error in eval(expr, envir, enclos) : object 'x' not found
In addition: Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf