-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Description
I don't know if this is an error or not, but is there a way to prevent character vectors in mappings to be turned into factors?
In the code below, I create a small graph and I provide a string vector for edge.id (and another, other_string, in case edge.id is treated specially (which doesn't seem to be the case)). I want to be able to map edge ids to other labels in a table, so I would like the vector(s) to be strings that I can access inside the aesthetics. I don't use a table in the example but a function so I can print the parameter, and that shows that these string vectors have been turned into factors.
library(tibble)
library(tidygraph)
library(ggraph)
nodes <- tribble(
~label,
"foo",
"bar",
"baz",
)
edges <- tribble(
~from, ~to, ~edge.id, ~other_string,
"foo", "bar", "foobar", "qux",
"foo", "baz", "foobaz", "qax"
)
tg <- tbl_graph(nodes = nodes, edges = edges)
tg
map_id <- function(ids) {
print(ids)
as.character(ids)
}
ggraph::ggraph(tg) +
ggraph::geom_edge_link(
aes(label = map_id(edge.id))
)
ggraph::ggraph(tg) +
ggraph::geom_edge_link(
aes(label = map_id(other_string))
)I can, of course, turn them back into strings, but that seems like a roundabout way to do this.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels