Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.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
有没有办法拆分相关矩阵,只显示其中的某一部分(R)?_R_Ggplot2_R Corrplot_Pearson Correlation_Ggcorrplot - Fatal编程技术网

有没有办法拆分相关矩阵,只显示其中的某一部分(R)?

有没有办法拆分相关矩阵,只显示其中的某一部分(R)?,r,ggplot2,r-corrplot,pearson-correlation,ggcorrplot,R,Ggplot2,R Corrplot,Pearson Correlation,Ggcorrplot,我有一个数据集随机化数据,对于我正在处理的这个例子,我只需要显示矩阵的某一部分。有没有办法保持代码中指定的参数不变,但只显示我需要的矩阵部分 我将在下面展示的代码生成如下所示的矩阵: 我喜欢所有东西的大小,尤其是右边的皮尔逊关联值图例。但是,我只需要在下图中显示红色框中的所有内容: 以下是我正在使用的代码: 数据: 代码: 我发现另一个解决方案是调整比例,以便裁剪出不需要的变量。这不是最技术性的答案,但它适用于我需要的参数: png("wholeplant.png", width=900, he

我有一个数据集随机化数据,对于我正在处理的这个例子,我只需要显示矩阵的某一部分。有没有办法保持代码中指定的参数不变,但只显示我需要的矩阵部分

我将在下面展示的代码生成如下所示的矩阵:

我喜欢所有东西的大小,尤其是右边的皮尔逊关联值图例。但是,我只需要在下图中显示红色框中的所有内容:

以下是我正在使用的代码:

数据:

代码:


我发现另一个解决方案是调整比例,以便裁剪出不需要的变量。这不是最技术性的答案,但它适用于我需要的参数:

png("wholeplant.png", width=900, height=600)
ggcorrplot(res, hc.order = FALSE, type = "lower",
           outline.col = "white",
           ggtheme = ggplot2::theme_gray,
           colors = c("#6D9EC1", "white", "#E46726"),
           lab = TRUE, lab_size = 7, show.diag=FALSE,
           legend.title = "r-value", tl.cex=17)+
  theme(
    #resize the legend width and height
    legend.key.width=unit(1, "cm"),
    legend.key.height=unit(1, "cm"),
    legend.title=element_text(size=20),
    legend.text=element_text(size=15),
    #Put it where it won't be out of the way
    legend.position = c(1.1, 0.2)
  )
dev.off()

我发现另一个解决方案是调整比例,以便裁剪出不需要的变量。这不是最技术性的答案,但它适用于我需要的参数:

png("wholeplant.png", width=900, height=600)
ggcorrplot(res, hc.order = FALSE, type = "lower",
           outline.col = "white",
           ggtheme = ggplot2::theme_gray,
           colors = c("#6D9EC1", "white", "#E46726"),
           lab = TRUE, lab_size = 7, show.diag=FALSE,
           legend.title = "r-value", tl.cex=17)+
  theme(
    #resize the legend width and height
    legend.key.width=unit(1, "cm"),
    legend.key.height=unit(1, "cm"),
    legend.title=element_text(size=20),
    legend.text=element_text(size=15),
    #Put it where it won't be out of the way
    legend.position = c(1.1, 0.2)
  )
dev.off()

我只是对d=d[d$Var2%in%paste0STAGE,1:3]部分有点困惑。在此处未显示的实际数据中,我有工厂阶段的实际名称;例如,阶段1=开花,阶段2=凹痕,阶段3=黑色层。如何更新此代码,使其适合数据的变量名?否则,根据我提供的数据,它可以完美地工作。谢谢。@ihb,d=d[d$Var2%in%cDent,黑色层,]我只是对d=d[d$Var2%in%paste0STAGE,1:3,]部分有点困惑。在此处未显示的实际数据中,我有工厂阶段的实际名称;例如,阶段1=开花,阶段2=凹痕,阶段3=黑色层。如何更新此代码,使其适合数据的变量名?否则,根据我提供的数据,它可以完美地工作。谢谢。@ihb,d=d[d$Var2%in%cDent,黑色层,]
library(reshape2)
library(ggplot2)

res <- cor(sen)
res[upper.tri(res)] = NA
diag(res) = NA
d = melt(res)
d = d[d$Var2 %in% paste0("STAGE", 1:3),]

graphics.off()
ggplot(d, aes(x = Var1, y = Var2, fill = value, label = round(value, 2))) +
    geom_tile(color = "black") +
    geom_text() +
    labs(fill = "r-value") +
    coord_equal()  #OPTIONAL
png("wholeplant.png", width=900, height=600)
ggcorrplot(res, hc.order = FALSE, type = "lower",
           outline.col = "white",
           ggtheme = ggplot2::theme_gray,
           colors = c("#6D9EC1", "white", "#E46726"),
           lab = TRUE, lab_size = 7, show.diag=FALSE,
           legend.title = "r-value", tl.cex=17)+
  theme(
    #resize the legend width and height
    legend.key.width=unit(1, "cm"),
    legend.key.height=unit(1, "cm"),
    legend.title=element_text(size=20),
    legend.text=element_text(size=15),
    #Put it where it won't be out of the way
    legend.position = c(1.1, 0.2)
  )
dev.off()