```{r setup, include=FALSE} knitr::opts_chunk$set(echo = FALSE) library(networkD3) library(dplyr)
datos_sankey <- datos %>% count(na_tamano, desgrasante_textura, na_ordenamiento)
nodos <- data.frame(name = unique(c(datos_sankey\(na_tamano, datos_sankey\)desgrasante_textura, datos_sankey$na_ordenamiento)))
enlaces_1 <- datos_sankey %>% group_by(na_tamano, desgrasante_textura) %>% summarise(value = sum(n), .groups = “drop”) %>% mutate(source = match(na_tamano, nodos\(name) - 1, target = match(desgrasante_textura, nodos\)name) - 1)
enlaces_2 <- datos_sankey %>% group_by(desgrasante_textura, na_ordenamiento) %>% summarise(value = sum(n), .groups = “drop”) %>% mutate(source = match(desgrasante_textura, nodos\(name) - 1, target = match(na_ordenamiento, nodos\)name) - 1)
enlaces <- bind_rows(enlaces_1, enlaces_2)
sankeyNetwork(Links = enlaces, Nodes = nodos, Source = “source”, Target = “target”, Value = “value”, NodeID = “name”, fontSize = 12, nodeWidth = 30)