Inproper show when using geom_net in R

Given a data frame:

v1     v2     v3     v4
Tom     A     Jim     B
Gary    A     Shirly  A
Shirly  B     Jack    B
Tom     A     Jack    B
...

v2 and v4 indicate which group the name belongs to in v1 and v3. The volume belongs to group A, and Jim belongs to group v4. I would like to build a social network with geom_net, with binding strings to two names, if they are on the same line, for example, Tomand Jim. And the size of the ribs should be proportional to the times of their appearance in V3, i.e. The edge Jackshould be twice as large as Jimand Shirly.

I tried

ggplot(df, aes(from_id = V1,to_id = V3)) +geom_net()

But a very bad result is given:   enter image description here

And a warning is generated:

In f(..., self = self) :
There are 35 nodes without node information:
#And the below are all the values in V1 and V3
Tom, Shirly, ....
Did you use all=T in merge?

, , x y, . , . , .

! !

+4
2

, , data.frame geom_net. , , data.frame, : 1 (, ), FROM TO. , ​​ , ,

ans <- read.table(text ="
from to linewidth
Tom Jim 0.1
Gary Shirly 1
Shirly Jack 0.5
Tom Jack 2
", sep = " ", stringsAsFactors = FALSE, header=TRUE)

p <- ggplot(data = ans, aes(from_id = from, to_id = to))
p + geom_net(label = TRUE, vjust=-1)

, () . , 2. data.frame. 2 , . , geom_net FROM node, TO node, , , , FROM.

ans <- read.table(text ="
from to linewidth
Tom Jim 0.1
Gary Shirly 1
Shirly Jack 0.5
Tom Jack 2
Helen Jack 3
Jim NA NA
Jack NA NA
", sep = " ", stringsAsFactors = FALSE, header=TRUE, na.strings = "NA")

p <- ggplot(data = ans, aes(from_id = from, to_id = to, linewidth = linewidth))
p + geom_net(label = TRUE, vjust=-1)

, : 1) "Jim NA NA Jack NA NA" , 2) na.strings = "NA", read.table() NA, 3) aes , data.frame .

, , , " XX node ".

, enter image description here edit: . geom_net() ,


data.frame, , data.frames, : data.frame (), - ().

lines <- read.table(text ="
from to linewidth
Tom Ivy 0.1
Gary Ivy 1
Shirly Ivy 0.5
Tom Helen 2
Helen Ivy 3
", sep = " ", stringsAsFactors = FALSE, header=TRUE, na.strings = "NA")

nodes <- read.table(text ="
name
Tom
Jim
Gary
Shirly
Jack
Helen
Susan
Joel
Ivy
", sep = " ", stringsAsFactors = FALSE, header=TRUE,na.strings = "NA")

df <- merge(lines, nodes, by.x = "from", by.y = "name", all = TRUE)

p <- ggplot(data = df, aes(from_id = from, to_id = to, linewidth = linewidth))
p + geom_net(label = TRUE, vjust=-1)

enter image description here

+1

. , github.com/sctyner/geomnet/issues. @hackR , . : , from_id to_id (+ ), id (+ ). :

network_data <- merge(edges, vertices, by.x = "from_id", by.y = "to_id", all = T)

all = T!

, .

0

Source: https://habr.com/ru/post/1625713/


All Articles