Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(tidyverse)
library(igraph)
library(ggraph)
library(abjutils)
df <- read_rds("data/socios_cvm.rds")
glimpse(df)
df_clean <- df %>%
filter(tipo == "02") %>%
mutate(denom_comerc = rm_accent(denom_comerc))
df_grafo <- df_clean %>%
select(nome, empresa = denom_comerc)
df_grafo <- inner_join(df_grafo, df_grafo, by = "nome") %>%
filter(empresa.x != empresa.y) %>%
select(empresa.x, empresa.y) %>%
na.omit() %>%
count(empresa.x, empresa.y, sort = TRUE)
df_grafo <- df_grafo %>%
rowwise() %>%
mutate(concat = paste0(sort(c(empresa.x, empresa.y)), collapse = "_")) %>%
ungroup()
df_grafo <- df_grafo %>%
distinct(concat, .keep_all = TRUE) %>%
select(-concat)
df_grafo
g <- graph_from_data_frame(df_grafo, directed = FALSE)
vcount(g)
g
g %>%
ggraph() +
geom_node_point() +
geom_edge_link(aes(alpha = n)) +
theme_graph() +
labs(title = "Interseção entre sócios em empresas da CVM")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment