R语言 相关图一列多组单图

zbdgwd5y  于 2023-02-20  发布在  其他
关注(0)|答案(2)|浏览(132)

我想要一个corrplot,这里我只有第一列。我从这里得到了解决方案:Corrplot with only one variable on x axis

  1. corrplot(cor(iris[,1:4])[1:4,1, drop=FALSE], cl.pos='n')

但我希望第一列按组重复同一地块内的数据:

我不是结婚使用corrplot,但需要一些类似的解决方案。感谢任何和所有的帮助。

eimct9ow

eimct9ow1#

下面是一个不需要额外软件包的简单方法:

  1. library(corrplot)
  2. Dat<-cor(iris[,1:4])[1:4,1, drop=FALSE]
  3. PlotDat<-cbind(Dat,Dat,Dat)
  4. corrplot(PlotDat, cl.pos='n')

z6psavjg

z6psavjg2#

如果要完全控制绘图,可以使用ggplot2执行类似的操作

  1. library(tidyverse)
  2. as.data.frame(cor(iris[1:4])[,rep(1, 3)]) %>%
  3. setNames(1:3) %>%
  4. rownames_to_column() %>%
  5. pivot_longer(-rowname) %>%
  6. mutate(rowname = factor(rowname, rev(unique(rowname)))) %>%
  7. ggplot(aes(name, rowname)) +
  8. geom_tile(fill = 'white', color = 'black') +
  9. geom_point(aes(size = abs(value), color = value)) +
  10. coord_equal() +
  11. scale_x_discrete(NULL, labels = rep('Sepal.Length', 3), expand = c(0, 0),
  12. position = 'top') +
  13. scale_y_discrete(NULL, expand = c(0, 0)) +
  14. scale_color_gradientn(colors = c('red3', 'red', 'white', '#4080ce', '#063062'),
  15. limits = c(-1, 1), guide = 'none') +
  16. scale_size_continuous(limits = c(0, 1), range = c(0, 20), guide = 'none') +
  17. theme(axis.text.x = element_text(angle = 90),
  18. plot.margin = margin(20, 20, 20, 20))

展开查看全部

相关问题