我想知道如何为矩阵相关热图添加另一层重要且需要的复杂性,例如除了R2值(-1到1)之外,在显着性水平星的方式之后的p值?
在这个问题中没有意图将显着性水平星或p值作为文本放在矩阵BUT的每个方格上,而不是在矩阵的每个方格上的显着性水平的图形开箱即用表示中 . 我认为只有那些享受创新思维祝福的人才能赢得掌声,解开这种解决方案,以便有最好的方式来代表我们的复杂性.Page 2619411_ . 我google了很多但从未见过正确或我会说"eye-friendly"方式来表示显着性水平加上反映R系数的标准色调 .
可重现的数据集可在此处找到:
http://learnr.wordpress.com/2010/01/26/ggplot2-quick-heatmap-plotting/
R代码请在下面找到:
library(ggplot2)
library(plyr) # might be not needed here anyway it is a must-have package I think in R
library(reshape2) # to "melt" your dataset
library (scales) # it has a "rescale" function which is needed in heatmaps
library(RColorBrewer) # for convenience of heatmap colors, it reflects your mood sometimes
nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv")
nba <- as.data.frame(cor(nba[2:ncol(nba)])) # convert the matrix correlations to a dataframe
nba.m <- data.frame(row=rownames(nba),nba) # create a column called "row"
rownames(nba) <- NULL #get rid of row names
nba <- melt(nba)
nba.m$value<-cut(nba.m$value,breaks=c(-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1),include.lowest=TRUE,label=c("(-0.75,-1)","(-0.5,-0.75)","(-0.25,-0.5)","(0,-0.25)","(0,0.25)","(0.25,0.5)","(0.5,0.75)","(0.75,1)")) # this can be customized to put the correlations in categories using the "cut" function with appropriate labels to show them in the legend, this column now would be discrete and not continuous
nba.m$row <- factor(nba.m$row, levels=rev(unique(as.character(nba.m$variable)))) # reorder the "row" column which would be used as the x axis in the plot after converting it to a factor and ordered now
#now plotting
ggplot(nba.m, aes(row, variable)) +
geom_tile(aes(fill=value),colour="black") +
scale_fill_brewer(palette = "RdYlGn",name="Correlation") # here comes the RColorBrewer package, now if you ask me why did you choose this palette colour I would say look at your battery charge indicator of your mobile for example your shaver, won't be red when gets low? and back to green when charged? This was the inspiration to choose this colour set.
矩阵相关热图应如下所示:
提高解决方案的提示和想法:
- 此代码可能有助于了解从本网站获取的重要级别明星:
http://ohiodata.blogspot.de/2012/06/correlation-tables-in-r-flagged-with.html
R代码:
mystars <- ifelse(p < .001, "***", ifelse(p < .01, "** ", ifelse(p < .05, "* ", " "))) # so 4 categories
- 显着性水平可以作为颜色强度添加到每个方格像alpha美学,但我不认为这将很容易解释和捕获
- 另一个想法是有4个不同大小的方块对应于星星,当然给出最小的非显着性,如果最高的星星则增加到全尺寸方块
- 另一个想法是在这些重要的正方形中包含一个圆,并且圆的线的粗细对应于显着性水平(其余3个类别),所有这些都是一种颜色
- 与上述相同但固定线条粗细,同时为3个剩余的重要级别提供3种颜色
- 你可能想出更好的想法,谁知道?
2 回答
这只是为了提升最终解决方案的尝试,我在这里绘制了星星作为解决方案的指标,但正如我所说,目标是找到一个比星星更好的图形解决方案 . 我只是使用geom_point和alpha来表示显着性水平,但是NA(包括非重要值)的问题将显示为三星级重要性的问题,如何解决这个问题?我认为使用一种颜色在使用多种颜色时可能会更加眼睛友好,并避免给情节加重许多细节以便眼睛解决 . 提前致谢 .
这是我第一次尝试的情节:
或者可能这样更好?!
我认为现在最好的是下面的那个,直到你想出更好的东西!
根据要求,以下代码适用于最后一个热图:
我希望这可以向前迈进一步!请注意:
为了表示估计相关系数的显着性,您可以改变着色量 - 使用
alpha
或仅填充每个图块的子集:这里的关键是p.values的缩放:为了获得仅在相关区域中显示大变化的易于理解的值,我使用由
fdrtools
提供的本地错误发现(lfdr)的上限估计 . 即,图块的alpha值可能小于或等于该相关的概率与0不同 .