-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathNetwork.R
92 lines (77 loc) · 3.55 KB
/
Network.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Differenent representations of the social network
# Type 1: Using the 'network' library
# Friends (using their initials)
friends.network <- as.network(friends.matrix)
plot(friends.network, label=friends.initial, arrowhead.cex=0)
# And writing to a PDF
pdf(file=paste("output/Network_Initials_",file.seqno,".pdf", sep=""), width=25, height=25)
plot(friends.network, label=friends.initial, arrowhead.cex=0)
dev.off()
file.seqno <- file.seqno + 1
# Friends (using their full names)
friends.network <- as.network(friends.matrix)
plot(friends.network, label=friends.name, arrowhead.cex=0)
# And writing to a PDF
pdf(file=paste("output/Network_Names_",file.seqno,".pdf", sep=""), width=25, height=25)
plot(friends.network, label=friends.name, arrowhead.cex=0)
dev.off()
file.seqno <- file.seqno + 1
# Type 2: Using the 'Rgraphviz' library
# Initial set up for the graph
# Create the graph
friends.graph <-graph.adjacency(friends.matrix,mode="undirected")
# Create a fixed layout
set.seed(1)
friends.layout <- layout.fruchterman.reingold(friends.graph)
# Rescale the layout to -1 to 1
friends.layout[,1]=(friends.layout[,1]-min(friends.layout[,1]))/(max(friends.layout[,1])-min(friends.layout[,1]))*2-1
friends.layout[,2]=(friends.layout[,2]-min(friends.layout[,2]))/(max(friends.layout[,2])-min(friends.layout[,2]))*2-1
# Friends (using their initials)
V(friends.graph)$label <- friends.initial
plot(friends.graph,layout=friends.layout,vertex.size=0,vertex.frame.color="#00000000")
# And writing to a PDF
pdf(file=paste("output/Network_Initials_",file.seqno,".pdf", sep=""), width=25, height=25)
plot(friends.graph,layout=friends.layout,vertex.size=0,vertex.frame.color="#00000000")
dev.off()
file.seqno <- file.seqno + 1
# Friends (using their names)
V(friends.graph)$label <- friends.name
plot(friends.graph,layout=friends.layout,vertex.size=0,vertex.frame.color="#00000000")
# And writing to a PDF
pdf(file=paste("output/Network_Names_",file.seqno,".pdf", sep=""), width=25, height=25)
plot(friends.graph,layout=friends.layout,vertex.size=0,vertex.frame.color="#00000000")
dev.off()
file.seqno <- file.seqno + 1
# Currently commented out until I can improve the speed and output size
#
# # Friends (using their photos)
# V(friends.graph)$label <- ""
# plot(friends.graph,layout=friends.layout,vertex.size=0,vertex.frame.color="#00000000")
#
# # Additional code required to add image
# friends.layout.tmp<-friends.layout
# for(i in length(friends.id):1){
# myfriend.photo<-read.jpeg(paste("photos/friends/",friends.id[i],".jpg",sep=""))
# if(i!=1){
# apply(friends.layout.tmp,1,function(x)rasterImage(myfriend.photo,x[1]-0.05,x[2]-0.05,x[1]+0.05,x[2]+0.05))
# friends.layout.tmp<-friends.layout.tmp[-i,]
# }else{
# rasterImage(myfriend.photo,friends.layout.tmp[1]-0.05,friends.layout.tmp[2]-0.05,friends.layout.tmp[1]+0.05,friends.layout.tmp[2]+0.05)
# }
# }
#
# # And writing to a PDF
# pdf(file=paste("output/Network_Photos_",file.seqno,".pdf", sep=""), width=25, height=25)
# plot(friends.graph,layout=friends.layout,vertex.size=0,vertex.frame.color="#00000000")
# friends.layout.tmp<-friends.layout
# for(i in length(friends.id):1){
# myfriend.photo<-read.jpeg(paste("photos/friends/",friends.id[i],".jpg",sep=""))
# if(i!=1){
# apply(friends.layout.tmp,1,function(x)rasterImage(myfriend.photo,x[1]-0.05,x[2]-0.05,x[1]+0.05,x[2]+0.05))
# friends.layout.tmp<-friends.layout.tmp[-i,]
# }else{
# rasterImage(myfriend.photo,friends.layout.tmp[1]-0.05,friends.layout.tmp[2]-0.05,friends.layout.tmp[1]+0.05,friends.layout.tmp[2]+0.05)
# }
# }
# dev.off()
# file.seqno <- file.seqno + 1