写一段R语言做桑基图的代码
时间: 2023-05-19 14:00:56 浏览: 239
python+echarts+excel制作桑基图
5星 · 资源好评率100%
Sure, here's an example code for creating a Sankey diagram in R:
library(networkD3)
library(tidyverse)
# Create a sample data frame
data <- data.frame(
from = c("A", "A", "B", "B", "C", "C"),
to = c("B", "C", "D", "E", "D", "E"),
value = c(10, 20, 30, 40, 50, 60)
)
# Create a networkD3 Sankey diagram
sankeyNetwork(
Links = data,
Source = "from",
Target = "to",
Value = "value",
NodeID = unique(c(data$from, data$to)),
sinksRight = FALSE,
fontSize = 16,
nodeWidth = 30
)
This code uses the networkD3 and tidyverse packages to create a Sankey diagram from a sample data frame. The resulting diagram shows the flow of values from the "from" nodes to the "to" nodes.
阅读全文