使用R美化Sankey /冲积可视化

use*_*413 7 charts r ggplot2 sankey-diagram

我目前正在使用R中的Alluvial包来创建可视化.

这是我的数据集:

https://app.box.com/s/6qju42u0cg1cmrnhyhyzmjtp59wnsn3q

这是我的代码:

alluvial(fb_ad_3d[,2:3], freq=fb_ad_3d$freq,
         col = ifelse( fb_ad_3d$Response == "Yes", "skyblue1", 
                       "darkorchid1" ),xw = 0.2,alpha = 0.6,
                        gap.width=0.2,cex = 1.1, cex.axis = 1.5)
Run Code Online (Sandbox Code Playgroud)

这是可视化:

在此输入图像描述

我真的不喜欢两件事:

  1. 流连接器边缘的锯齿形图案

  2. 左侧的某些类别(农业,事件,电子,电信)已被压缩,使其不合格.

有什么方法可以改善这种可视化并使其美观?

use*_*413 12

试过ggalluvial包裹.结果好多了.

这是代码:

A_col <- "firebrick3"
B_col <- "darkorange"
C_col <- "deepskyblue3"
alpha <- 0.7

ggplot(fb_ad_3d,
       aes(weight = freq, axis1 = Category, axis2 = Response)) +
  geom_alluvium(aes(fill = Response, color = Response), 
                width = 1/12, alpha = alpha, knot.pos = 0.4) +
  geom_stratum(width = 1/6, color = "grey") +
  geom_label(stat = "stratum", label.strata = TRUE) +
  scale_x_continuous(breaks = 1:2, labels = c("Category", "Response"))     +
  scale_fill_manual(values  = c(A_col, B_col, C_col)) +
  scale_color_manual(values = c(A_col, B_col, C_col)) +
  ggtitle("Relevance of Facebook Custom List Advertising") +
  theme_minimal() +
  theme(
   axis.text.x = element_text(size = 12, face = "bold")
  )
Run Code Online (Sandbox Code Playgroud)

这是可视化:

在此输入图像描述

  • 尝试使用以下内容:`theme(legend.position ="none",panel.grid.major = element_blank(),panel.grid.minor = element_blank(),axis.text.y = element_blank(),axis.text .x = element_text(size = 12,face ="bold"))` (3认同)