R-corrplot包-相关性可视化2

1.8

cl.pos图例位置


1corrplot(mat_cor, method = "ellipse", order = "AOE",  col = palette_2, 
2         addCoef.col = "gray20", addCoefasPercent = TRUE, cl.pos = "r", 
3         title = "图例在右边", diag = TRUE, mar = c(1,1,1,1))
4corrplot(mat_cor, method = "ellipse", order = "AOE",  col = palette_2, 
5         addCoef.col = "gray20", addCoefasPercent = TRUE, cl.pos = "b", 
6         title = "图例在底部", diag = TRUE, mar = c(1,1,1,1))
7corrplot(mat_cor, method = "ellipse", order = "AOE",  col = palette_2, 
8         addCoef.col = "gray20", addCoefasPercent = TRUE, cl.pos = "n", 
9         title = "无图例", diag = TRUE, mar = c(1,1,1,1))


1.9

变量文本tl.pos、tl.cex及tl.col


tl.pos只有在混合布局的时候才有意义。

1corrplot(mat_cor, method = "ellipse", order = "AOE",  col = palette_2, 
2         addCoef.col = "gray20", addCoefasPercent = TRUE, cl.pos = "r", 
3         tl.pos = "lt",tl.cex = 2, tl.col = "blue",
4         title = "蓝色变量文本", diag = TRUE, mar = c(1,1,1,1))
5
6corrplot(mat_cor, method = "ellipse", order = "AOE",  col = palette_2, 
7         addCoef.col = "gray20", addCoefasPercent = TRUE, cl.pos = "r", 
8         tl.pos = "n",
9         title = "无变量文本", diag = TRUE, mar = c(1,1,1,1))


1.10

阴影设置


只有当method="shade"时,该参数才有用。
addshade添加阴影范围,分为正阴影,负阴影,全阴影。
shade.lwd设置阴影线宽。shade.col设置阴影线颜色。

1corrplot(mat_cor, method = "shade", order = "AOE", col = palette_2, 
2         addshade = "negative", shade.lwd = 1, shade.col = "blue",   
3         title = "蓝色负阴影", mar = c(1,1,1,1))
4corrplot(mat_cor, method = "shade", order = "AOE", col = palette_2, 
5         addshade = "positive", shade.lwd = 1, shade.col = "blue", 
6         title = "蓝色正阴影", mar = c(1,1,1,1))
7corrplot(mat_cor, method = "shade", order = "AOE", col = palette_2, 
8         shade.lwd = 1, shade.col = "blue", 
9         title = "默认全阴影", mar = c(1,1,1,1))


1.11

显著性标记sig.level及p.mat


只有指定矩阵的P值,sig.level,pch等参数才有效。
只有当insig = "pch"时,pch.col和pch.cex参数才有效。
对于p值不清楚的同学,可以参考 知乎的答案

(https://www.zhihu.com/question/23149768)
概况起来,就一句话:小于p值的不可能信,没有意义。

 1library(corrplot)
 2
 3res1 <- cor.mtest(mtcars, conf.level = .95)
 4
 5corrplot(mat_cor, method = "circle",  col = palette_2,
 6         p.mat = res1$p, sig.level = 0.01, 
 7         title = "增加显著性标记", mar = c(1,1,1,1))
 8
 9corrplot(mat_cor, method = "circle",  col = palette_2,
10         p.mat = res1$p, sig.level = 0.01, insig = "pch", pch.col = "blue", pch.cex = 3,
11         title = "蓝色显著性标记", mar = c(1,1,1,1))
12


1.12

add混合布局


add参数表示是否添加到已经存在的plot中。默认FALSE生成新plot。

 1# 第一个图,
 2corrplot(mat_cor, method = "ellipse", type = "upper", order = "AOE", 
 3         col = palette_2, tl.pos = "d",
 4         title = "上椭圆下百分比混合布局", mar = c(1,1,1,1))
 5corrplot(mat_cor, method = "number", type = "lower", order = "AOE", col = palette_2,
 6         add = TRUE, diag = FALSE, tl.pos = "n", addCoefasPercent = TRUE, cl.pos = "n", 
 7         mar = c(1,1,1,1))
 8# 第2个图,
 9corrplot(mat_cor, method = "pie", type = "lower", order = "AOE", 
10         col = palette_2, tl.pos = "tp", tl.col = "blue", cl.pos = "r", 
11         title = "上数字下饼图混合布局", mar = c(1,1,1,1))
12corrplot(mat_cor, method = "number", type = "upper", order = "AOE", col = palette_2,
13         add = TRUE, diag = FALSE, tl.pos = "n", cl.pos = "n", 
14         mar = c(1,1,1,1))


2.ggcorrplot包
ggcorrplot包内就2个函数,一个cor_pmat()用于计算p值, 一个ggcorrplot()用于绘图。
ggcorrplot相当于精简版的corrplot包。只有主题更加丰富多样。

2.1

语法及参数


语法:

1ggcorrplot(corr, method = c("square", "circle"), type = c("full", "lower",
2  "upper"), ggtheme = ggplot2::theme_minimal, title = "",
3  show.legend = TRUE, legend.title = "Corr", show.diag = FALSE,
4  colors = c("blue", "white", "red"), outline.color = "gray",
5  hc.order = FALSE, hc.method = "complete", lab = FALSE,
6  lab_col = "black", lab_size = 4, p.mat = NULL, sig.level = 0.05,
7  insig = c("pch", "blank"), pch = 4, pch.col = "black", pch.cex = 5,
8  tl.cex = 12, tl.col = "black", tl.srt = 45, digits = 2)


关键参数:

method,相比corrplot,少了很多种,只有方形和圆形,默认方形。

colors,需要长度为3的颜色向量,同时指定low,mid和high处的颜色。

outline.color,指定方形或圆形的边线颜色。

hc.order,是否按hclust(层次聚类顺序)排列。

hc.method,相当于corrplot中的hclust.method, 指定方法一样,详情见?hclust。

lab, 是否添加相关系数。

lab_col,指定相关系数的颜色,只有当lab=TRUE时有效。

lab_size,指定相关系数大小,只有当lab=TRUE时有效。

show.legend, 是否显示图例。

legend.title,指定图例标题。

sig.level,insig,pch,pch.col,pch.cex,与corrplot中完全一样。

tl.cex, 指定变量文本的大小,

tl.col, 指定变量文本的颜色,

tl.srt, 指定变量文本的旋转角度。

digits, 指定相关系数的显示小数位数(默认2)。

2.2

实例


 1library(ggplot2)
 2library(ggcorrplot)
 3library(showtext)
 4
 5# 更改字体
 6windowsFonts(YaHei_rontine = windowsFont("微软雅黑"),
 7             Time_NewR = windowsFont("Times New Romans 常规"))
 8font_add("YaHei_rontine", regular = "msyh.ttc", bold = "msyhbd.ttc")
 9font_add("Time_NewR", "times.ttf", 
10         bold = "timesbd.ttf", 
11         italic = "timesi.ttf", 
12         bolditalic = "timesbd.ttf")
13
14showtext_auto()
15
16# 自定义主题
17mytheme <- theme_bw() +
18  theme(
19    plot.title = element_text(colour = "blue", hjust = 0.5, size = 20), 
20    legend.text = element_text(colour = "blue"), 
21    legend.title = element_text(family = "YaHei_rontine", colour = "blue"), 
22    legend.position = "bottom", legend.direction = "horizontal"
23    )
24
25
26# 绘图
27ggcorrplot(mat_cor, 
28           method="circle", 
29           hc.order = TRUE, 
30           type = "lower", 
31           lab = TRUE,  # 显示相关系数
32           lab_col = "blue", lab_size = 3, 
33           colors = c("cyan", "white", "magenta"), 
34           tl.cex = 10, tl.col = "blue", digits = 1, 
35           title="下三角圆形,hclust排列", 
36           legend.title = "相关系数", 
37           ggtheme = theme_bw())
38
39# 自定义主题
40ggcorrplot(mat_cor, 
41           method="circle", 
42           hc.order = TRUE, 
43           type = "lower", 
44           lab = TRUE,  # 显示相关系数
45           lab_col = "blue", lab_size = 3, 
46           colors = c("cyan", "white", "magenta"), 
47           tl.cex = 10, tl.col = "blue", digits = 1, 
48           title="自定义主题", 
49           legend.title = "相关系数", 
50           ggtheme = mytheme)


2.3

显著性标记


 1library(ggplot2)
 2library(ggcorrplot)
 3
 4p_mat <- cor_pmat(mtcars)
 5
 6ggcorrplot(mat_cor, 
 7           method="circle", hc.order = TRUE, type = "lower", 
 8           lab = TRUE,  lab_col = "blue", lab_size = 3, # 显示相关系数
 9           colors = c("cyan", "white", "magenta"), 
10           tl.cex = 10, tl.col = "blue", digits = 1, 
11           title="显著性标记", 
12           legend.title = "相关系数", 
13           p.mat = p_mat, 
14           ggtheme = theme_bw())
15
16ggcorrplot(mat_cor, 
17           hc.order = TRUE, type = "full", 
18           colors = c("cyan", "white", "magenta"), 
19           tl.cex = 10, tl.col = "blue", digits = 1, 
20           title="低于p值为空", 
21           legend.title = "相关系数", 
22           p.mat = p_mat, insig = "blank", 
23           ggtheme = theme_bw())
24
25ggcorrplot(mat_cor, 
26           method="circle", hc.order = TRUE, type = "upper", 
27           colors = c("cyan", "white", "magenta"), 
28           tl.cex = 10, tl.col = "blue", digits = 1, 
29           title="红色显著性标记", 
30           legend.title = "相关系数", 
31           p.mat = p_mat, insig = "pch", pch.col = "red", pch.cex = 4, 
32           ggtheme = theme_bw())
33

————————————————
版权声明:本文为CSDN博主「R语言中文社区」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/kMD8d5R/article/details/89346064

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: cv2.MIXED_CLONE是OpenCV中的一个函数,用于实现图像混合克隆。它可以将一个图像中的一个区域无缝地复制到另一个图像中,并将其与周围像素进行混合,以使过渡更自然。该函数需要以下参数: - src:源图像,应该是一个三通道的图像,数据类型为np.uint8。 - dst:目标图像,应该是一个三通道的图像,与src具有相同的形状和数据类型。 - mask:掩码图像,确定源图像中哪些区域应该被复制到目标图像中。它应该是一个单通道的图像,数据类型为np.uint8,其值应该为0或255。 - center:源图像中被复制区域的中心点在目标图像中的位置。 - mixed_clone:指定混合克隆的类型。可以是cv2.NORMAL_CLONE或cv2.MIXED_CLONE。 使用cv2.MIXED_CLONE函数可以实现很多有趣的应用,例如将一个人的脸部特征无缝地合并到另一个人的照片中。 ### 回答2: cv2.MIXED_CLONE是OpenCV中的一个函数,用于执行图像混合操作。它可以将源图像的某一区域无缝地融合到目标图像中的特定位置上。 cv2.MIXED_CLONE的使用涉及以下几个步骤: 首先,需要准备一个目标图像和一个源图像。目标图像是用来接收被融合区域的图像,而源图像是指定待融合的区域。 然后,需要确定融合操作的区域范围。可以通过生成一个掩膜来指定需要融合的区域。掩膜是一个和目标图像大小相同的二值图像,在融合区域上取值为非零,其他区域取值为零。 接下来,调用cv2.mixeClone函数进行融合操作。该函数需要传入目标图像、源图像、掩膜以及融合区域的起始坐标作为参数。 最后,融合结果将会返回给调用者,可以将其保存为一个输出图像。 cv2.MIXED_CLONE的工作原理是根据源图像和目标图像的灰度值与掩膜的像素值之间的权重关系,进行像素级的融合计算。该函数采用了一个优化算法,可以处理多层次的融合操作,以达到更好的效果。 ### 回答3: cv2.MIXED_CLONE是OpenCV图像处理库中的一个函数,用于将源图像中的某个区域克隆到目标图像中的对应位置。该函数采用克隆融合的方式,旨在以尽可能无缝的方式将源图像的特定区域与目标图像进行融合。 具体而言,cv2.MIXED_CLONE函数的调用方式如下: dst = cv2.seamlessClone(src, dst, mask, center, cv2.MIXED_CLONE) 其中,src表示源图像,dst表示目标图像,mask表示源图像中待克隆区域的蒙版,center为待克隆区域在目标图像中的中心位置,cv2.MIXED_CLONE表示克隆的融合方式。 在实际使用中,首先需要将待克隆的区域在源图像中进行标记,将标记结果作为mask参数传入cv2.MIXED_CLONE函数。接着,通过指定待克隆区域在目标图像中的中心位置,确定克隆的位置。最后,调用cv2.MIXED_CLONE函数,将源图像中的待克隆区域融合到目标图像中。 cv2.MIXED_CLONE函数的融合方式是综合了纹理、颜色和边缘等特征,以最小化融合边缘上的伪影和人工痕迹。这种融合方式在保持图像连续性和真实性的基础上,提供了较好的克隆效果。 总之,cv2.MIXED_CLONE是OpenCV图像处理库中一个用于克隆融合的函数,通过对源图像和目标图像进行相应的处理,可以实现将源图像中的特定区域无缝融合到目标图像中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值