我目前正在 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)

这是可视化:

r - 使用 R 美化 Sankey/Alluvial 可视化-LMLPHP

有两件事我真的不喜欢:
  • 流连接器边缘的锯齿形图案
  • 左侧的某些类别(农业、事件、电子、电信)已被压缩,因此不符合条件。

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

    最佳答案

    尝试了 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")
      )
    

    这是可视化:

    r - 使用 R 美化 Sankey/Alluvial 可视化-LMLPHP

    关于r - 使用 R 美化 Sankey/Alluvial 可视化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50395027/

    10-12 17:44