Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何按组为corrplot的背景着色?_R_Ggplot2_Matrix_Data Visualization_R Corrplot - Fatal编程技术网

如何按组为corrplot的背景着色?

如何按组为corrplot的背景着色?,r,ggplot2,matrix,data-visualization,r-corrplot,R,Ggplot2,Matrix,Data Visualization,R Corrplot,考虑这些数据,我们有几个组,每个组有10个观察值,我们进行了一次成对.t.测试(): 有人知道根据分组标签给每个正方形的背景上色的方法吗?例如,假设我们希望组a:g的方块为黄色,组h:n的方块为蓝色,组o:r的方块为红色。或者是否有其他方法可以使用ggplot?您可以通过bg=参数传递背景色向量。诀窍在于确保它们的顺序正确。这是做这件事的方法 bgcolors <- matrix("white", nrow(pmat), ncol(pmat),dimnames = d

考虑这些数据,我们有几个组,每个组有10个观察值,我们进行了一次
成对.t.测试()


有人知道根据分组标签给每个正方形的背景上色的方法吗?例如,假设我们希望组
a:g
的方块为黄色,组
h:n
的方块为蓝色,组
o:r
的方块为红色。或者是否有其他方法可以使用
ggplot

您可以通过
bg=
参数传递背景色向量。诀窍在于确保它们的顺序正确。这是做这件事的方法

bgcolors <- matrix("white", nrow(pmat), ncol(pmat),dimnames = dimnames(pmat))
bgcolors[1:6, ] <- "yellow"
bgcolors[7:15, ] <- "blue"
bgcolors[14:17, ] <- "red"
bgcolors <- bgcolors[lower.tri(bgcolors, diag=TRUE)]
corrplot(pmat, insig = "blank", type = "lower", bg=bgcolors)

bgcolors替代方法当然可以是使用
ggcorrplot
包()。
bgcolors <- matrix("white", nrow(pmat), ncol(pmat),dimnames = dimnames(pmat))
bgcolors[1:6, ] <- "yellow"
bgcolors[7:15, ] <- "blue"
bgcolors[14:17, ] <- "red"
bgcolors <- bgcolors[lower.tri(bgcolors, diag=TRUE)]
corrplot(pmat, insig = "blank", type = "lower", bg=bgcolors)