我想繪製相關矩陣,它應該是交互式的,並在ggplot2或plot_ly中顯示相關值和相應的p值。交互相關矩陣
我試過下面的代碼。
library(ggplot2)
library(plotly)
library(reshape)
library(Hmisc)
x <- Seatbelts
y <- as.matrix(x)
rt <- rcorr(y)
mtlr <- melt(rt$r)
mtlp <- melt(rt$P)
gx <- ggplot(mtl, aes(X1, X2, fill = value)) + geom_tile() +
scale_fill_gradient(low = "cyan", high = "red")
ggplotly(gx)
我想在同一圖表中顯示「mtlp」值。
任何人都可以幫忙嗎?
作爲第一個步驟中,您可以嘗試兩個data.frames合併'mtlr'and 'mtlp'合爲一體。在包'dplyr'中查找'merge()'函數或'_join()'函數。 – ottlngr
它不是合併值的問題。 rt < - rcorr(y)已包含兩個數據幀。問題是當我將光標懸停在單個單元格中時,我可以如何調用這兩個值(相關性和p值)。 –