facet_graph | R Documentation |
This function is equivalent to ggplot2::facet_grid()
in that it
allows for building a grid of small multiples where rows and columns
correspond to a specific data value. While ggplot2::facet_grid()
could be used it would lead to unexpected results as it is not possible to
specify whether you are referring to a node or an edge attribute. Furthermore
ggplot2::facet_grid()
will draw edges in panels even though the
panel does not contain both terminal nodes. facet_graph
takes care of
all of these issues, allowing you to define which data type the rows and
columns are referencing as well as filtering the edges based on the nodes in
each panel (even when nodes are not drawn).
facet_graph(
facets,
row_type = "edge",
col_type = "node",
margins = FALSE,
scales = "fixed",
space = "fixed",
shrink = TRUE,
labeller = "label_value",
as.table = TRUE,
switch = NULL,
drop = TRUE
)
facets |
|
row_type , col_type |
Either |
margins |
Either a logical value or a character
vector. Margins are additional facets which contain all the data
for each of the possible values of the faceting variables. If
|
scales |
Are scales shared across all facets (the default,
|
space |
If |
shrink |
If |
labeller |
A function that takes one data frame of labels and
returns a list or data frame of character vectors. Each input
column corresponds to one factor. Thus there will be more than
one with |
as.table |
If |
switch |
By default, the labels are displayed on the top and
right of the plot. If |
drop |
If |
Other ggraph-facets:
facet_edges()
,
facet_nodes()
library(tidygraph)
gr <- as_tbl_graph(highschool) %>%
mutate(popularity = as.character(cut(centrality_degree(mode = 'in'),
breaks = 3,
labels = c('low', 'medium', 'high')
)))
ggraph(gr) +
geom_edge_link() +
geom_node_point() +
facet_graph(year ~ popularity)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.