briatte / ggnetwork

Geoms to plot networks with ggplot2
https://briatte.github.io/ggnetwork/
146 stars 28 forks source link

Allow vertex/edge character attributes to be imported as such #53

Closed briatte closed 5 years ago

briatte commented 5 years ago

Right now, and unless the stringsAsFactors option has been modified globally, ggnetwork automatically converts strings to factors when importing vertex and edge attributes:

> data(emon, package = "network")
> str(ggnetwork(emon[[1]]))
'data.frame':   97 obs. of  15 variables:
 $ x                  : num  0.0791 0 0.6149 0.0471 0.5285 ...
 $ y                  : num  0.5645 0.3514 0.3141 0.0463 1 ...
 $ Command.Rank.Score : num  0 10 3 5 0 0 20 40 10 30 ...
 $ Decision.Rank.Score: num  20 7 0 5 0 0 20 50 10 20 ...
 $ Formalization      : num  2 1 1 1 1 1 1 2 1 3 ...
 $ Location           : Factor w/ 1 level "L": 1 1 1 1 1 1 1 1 1 1 ...
 $ na.x               : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
 $ Paid.Staff         : num  10 400 200 60 1 7 60 7 70 100 ...
 $ Sponsorship        : Factor w/ 6 levels "City","County",..: 6 6 6 4 5 5 2 3 1 1 ...
 $ vertex.names       : Factor w/ 14 levels "A.1.Ambulance.Service",..: 12 14 13 4 9 10 8 5 2 3 ...
 $ Volunteer.Staff    : num  50 2000 0 0 20 80 20 100 0 0 ...
 $ xend               : num  0.0791 0 0.6149 0.0471 0.5285 ...
 $ yend               : num  0.5645 0.3514 0.3141 0.0463 1 ...
 $ Frequency          : num  NA NA NA NA NA NA NA NA NA NA ...
 $ na.y               : logi  NA NA NA NA NA NA ...

Let's keep that default behaviour, but allow the user to change it if need be.

The problem above is shown with fortify.network. It also affects fortify.igraph, which suffers from another issue on top of that one: see #54.