forked from briatte/ggnet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot.R
54 lines (46 loc) · 1.24 KB
/
plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require(network)
require(RColorBrewer)
setwd("~/Documents/Code/R/ggnet/")
source("data.R")
source("functions.R")
source("ggnet.R")
# network
net = network(df)
mps = data.frame(Twitter = network.vertex.names(net))
# colours
mp.groups = merge(mps, ids, by = "Twitter")$Groupe
mp.colors = brewer.pal(9, "Set1")[c(3, 1, 9, 6, 8, 5, 2)]
# first example plot
ggnet(net,
weight = "degree",
quantize = TRUE,
node.group = mp.groups,
node.color = mp.colors,
names = c("Group", "Links")) +
theme(text = element_text(size = 16))
## ggsave(file = "example1.png")
# network density
ggnet(net,
size = 6,
segment.size = 0,
weight = "indegree",
legend = "none") +
geom_density2d()
## ggsave(file = "example2.png")
# rightwing parties
rightwing = ifelse(mp.groups == "NI", NA, mp.groups %in% c("UDI", "UMP"))
ggnet(net,
node.group = rightwing,
alpha = .25,
name = "Rightwing group")
## ggsave(file = "example3.png")
# followers of NKM
follows.nkm = ids$Twitter %in% who.follows(df, "nk_m")$followers
ggnet(net,
size = 6,
node.group = follows.nkm,
alpha = .25,
name = "Follows NKM",
label = "nk_m",
color = "black")
## ggsave(file = "example4.png")