如何在R中的ggraph plot中添加标题和修改调色板

new9mtju  于 2023-11-14  发布在  其他
关注(0)|答案(2)|浏览(161)

我正在使用R中的seeggraph包绘制相关图,但我不能添加图的标题,也不能更改调色板。提供的MWE如下:

library(tidyverse) # for `%>%` and probably others
library(see) # for plotting
library(ggraph) # needs to be loaded
library(correlation) # obviously for `correlation`, which I noticed was installed as a dependency of pkg:see but apparently not loaded with it.

mtcars %>% 
correlation(partial = TRUE) %>% 
plot()

字符串

58wvjzkj

58wvjzkj1#

要更改边缘颜色比例,需要使用ggraph中的scale_edge_color*函数之一:

library(correlation)
library(ggraph)
library(ggplot2)

p <- plot(correlation(mtcars, partial = TRUE)) +
  scale_edge_color_gradientn(colours = c("red3", "gray90", "green4")) +
  ggtitle("Partial correlation of mtcars dataset") +
  coord_equal(clip = "off")

p

字符串


的数据
在plotting函数中更改固定美学参数的选项似乎有限,但您可以更改生成的ggplot对象的图层。您也可以像往常一样在ggplot中更改主题元素:

p$layers[[2]]$aes_params$colour <- "navy"
p$layers[[3]]$aes_params$size <- 6

p + theme(plot.background = element_rect(fill = "skyblue"),
          plot.title = element_text(hjust = 0.5))


dohp0rv5

dohp0rv52#

希望这能让你接近你想要的,何塞:

cor_matrix <- cor(mtcars, method='pearson',use='complete.obs')
ggcorrplot(cor_matrix, method = c("square"), type = c("full"), 
           ggtheme = ggplot2::theme_minimal, 
           title = "Practice Title", show.legend = TRUE, 
           legend.title = "Corr", 
           show.diag = FALSE, outline.color = "gray", hc.order = TRUE, 
           lab = TRUE, 
           lab_col = "black", 
           lab_size = 2, tl.cex = 10, tl.col = "black", tl.srt = 45, digits = 2) + 
  theme(
   legend.key.width = unit(.6, "cm"),   #to resize legend
   legend.key.height = unit(1.4, "cm"),
  )

字符串

相关问题