Reputation: 871
I've built a dendrogram using ggraph and igraph.
library(ggraph)
library(igraph)
EL <- read.csv("EL2.csv", sep=";",header=TRUE, stringsAsFactors = FALSE)
ELM <-as.matrix(EL)
mygraph <- graph_from_data_frame(ELM)
ggraph(mygraph, layout = 'dendrogram', circular = TRUE) +
geom_edge_diagonal() +
geom_node_point() +
theme_void()
However, I need the underlying data for nodes and edges to recreate it in Tableau.
I wanted to use ggplot_build, but that requires a ggplot object. In order to create that I'm trying to use ig2ggplot, but it returns an error:
ig2ggplot(mygraph, dfOnly = FALSE, labels = FALSE, metab = TRUE)
Error in layout.norm(g$layout, xmax = 1, xmin = 0, ymin = 0, ymax = 1) : `layout' not a matrix
Does that mean I have to turn my igraph into a matrix? Because the plot looks exactly like I want it to look. I'm just trying to get hold off the underlying data. Any help would be appreciated on how to turn my igraph into a ggplot.
Edit: data with dput() (sorry, haven't used this before so I don't know if it's correct)
dput(EL) structure(list(from = c("Indo-European", "Albanian", "Gheg", "Albanian", "Tosk", "Tosk", "Tosk", "Indo-European", "Armenian", "Armenian", "Indo-European", "Balto-Slavic", "Baltic", "Eastern", "Eastern", "Eastern", "Eastern", "Baltic", "Western", "Balto-Slavic", "Slavic", "East", "East", "East", "East", "Slavic", "South", "South Eastern", "South Eastern", "South Eastern", "South", "South Western", "South Western", "South Western", "South Western", "South Western", "Slavic", "West", "Czech-Slovak", "Czech-Slovak", "West", "Lechitic", "Lechitic", "Lechitic", "West", "Sorbian", "Sorbian", "Indo-European", "Celtic", "Insular", "Brythonic", "Brythonic", "Brythonic", "Insular", "Goidelic", "Goidelic", "Goidelic", "Indo-European", "Germanic", "North Germanic", "East Scandinavian", "East Scandinavian", "Danish-Swedish", "Danish-Bokmal", "Danish-Swedish", "Danish-Riksmal", "Danish-Swedish", "North Germanic", "West Scandinavian", "West Scandinavian", "Germanic", "West Germanic", "English", "English", "West Germanic", "Frisian", "Frisian", "Frisian", "West Germanic", "High German", "German", "German", "Middle German", "East Middle German", "East Middle German", "East Middle German", "East Middle German", "Middle German", "West Middle German", "West Middle German", "West Middle German", "West Middle German", "Moselle Franconian", "German", "Upper German", "Upper German", "Alemannic", "Alemannic", "Alemannic", "Alemannic", "Upper German", "Bavarian-Austrian", "Bavarian-Austrian", "Bavarian-Austrian", "Bavarian-Austrian", "High German", "Yiddish", "Yiddish", "West Germanic", "Low Saxon-Low Franconian", "Low Franconian", "Low Franconian", "Low Franconian", "Low Franconian", "Low Franconian", "Low Saxon-Low Franconian", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Low Saxon", "Indo-European", "Greek", "Attic", "Attic", "Attic", "Attic", "Attic", "Greek", "Doric"), to = c("Albanian", "Gheg", "Gheg Albanian", "Tosk", "Arbereshe Albanian", "Arvanitika Albanian", "Tosk Albanian", "Armenian", "Armenian (language)", "Western Armenian", "Balto-Slavic", "Baltic", "Eastern", "Latgalian", "Standard Latvian", "Lithuanian", "Samogitian", "Western", "Prussian", "Slavic", "East", "Belarusian", "Russian", "Rusyn", "Ukrainian", "South", "South Eastern", "Bulgarian", "Macedonian", "Church Slavonic", "South Western", "Bosnian", "Croatian", "Montenegrin", "Serbian", "Slovene", "West", "Czech-Slovak", "Czech", "Slovak", "Lechitic", "Kashubian", "Polish", "Silesian", "Sorbian", "Lower Sorbian", "Upper Sorbian", "Celtic", "Insular", "Brythonic", "Breton", "Cornish", "Welsh", "Goidelic", "Irish", "Manx", "Scottish Gaelic", "Germanic", "North Germanic", "East Scandinavian", "Oevdalian", "Danish-Swedish", "Danish-Bokmal", "Norwegian", "Danish-Riksmal", "Danish", "Swedish", "West Scandinavian", "Faroese", "Icelandic", "West Germanic", "English", "English (language)", "Scots", "Frisian", "Frisian (language)", "Northern Frisian", "Saterfrisian", "High German", "German", "Hunsrik", "Middle German", "East Middle German", "Standard German", "Upper Saxon", "Lower Silesian", "Wymysory", "West Middle German", "Pennsylvania German", "Palatinate Franconian", "Ripurian", "Moselle Franconian", "Luxembourgish", "Upper German", "Eastern Franconian", "Alemannic", "Colonia Tovar German", "Swiss German", "Swabian", "Walser", "Bavarian-Austrian", "Bavarian", "Cimbrian", "Hutterisch", "Mocheno", "Yiddish", "Eastern Yiddish", "Western Yiddish", "Low Saxon-Low Franconian", "Low Franconian", "Afrikaans", "Dutch", "Limburgish", "Vlaams", "Zeeuws", "Low Saxon", "Achterhoeks", "Drents", "Gronings", "Plautdietsch", "Sallands", "East Frisian Low Saxon", "Low Saxon", "Stellingwerfs", "Twents", "Veluws", "Westphalien", "Greek", "Attic", "Cappadocian Greek", "Greek (language)", "Ancient Greek", "Pontic", "Yevanic", "Doric", "Tsakonian")), class = "data.frame", row.names = c(NA, -136L))
Upvotes: 2
Views: 2946
Reputation: 271
a layout tells igraph
where the x and y location for each node is for a plot. ig2ggplot requires that a layout is stored as a graph attribute. You will need to do something like this
mygraph <- igraph::graph_from_data_frame(ELM) #create a graph
mylayout <- igraph::layout_as_tree(mygraph, circular = T) #create a circular layout
mygraph$layout = mylayout #store layout as a graph attribute
#another gotcha is that ig2ggplot needs both vertex names and vertex labels.
#as of now you just have vertex names.
V(mygraph)$label = V(mygraph)$name #store label as a vertex attrbute
MetamapsDB::ig2ggplot(mygraph,
dfOnly = FALSE,
labels = FALSE,
metab = TRUE ) +
theme(legend.position = 'none')
Upvotes: 4