@@ -16,15 +16,19 @@ start.rec.log(text="CharComp")
1616
1717# ###############################################################################
1818# main parameters
19- filtered <- FALSE
20- filt.txt <- if (filtered ) " filtered" else " unfiltered"
2119
20+ # pair of characters to consider
2221chars <- c(" Thorgal Aegirsson" ," Jolan Thorgalsson" )
22+ pal <- get.palette(5 )[c(1 ,4 )]
23+
24+ # measures to compute
25+ meass <- c(MEAS_DEGREE , MEAS_BETWEENNESS , MEAS_CLOSENESS , MEAS_EIGENCNTR , MEAS_STRENGTH )
2326
2427
2528
2629
2730# ###############################################################################
31+ filt.txt <- if (filtered ) " filtered" else " unfiltered"
2832tlog(0 ," Load data and network" )
2933
3034# read raw data
@@ -37,95 +41,124 @@ scene.stats <- data$scene.stats
3741
3842# monitored characters
3943chars.short <- char.stats [match(chars ,char.stats [,COL_NAME ]),COL_NAME_SHORT ]
40- pal <- get.palette(5 )[c(1 ,4 )]
4144
42- # monitored volumes
43- # vols <- c(
44- # "28", "29",
45- # "30", "31", "32",#"K1",
46- # "33", #"L1", "K2",
47- # "K3", #"L2", "J1", "L3",
48- # "K4", "34", #"J2","L4",
49- # "K5", #"L5", "J3",
50- # "K6", #"J4","L6",
51- # "35"
52- # )
53- vols <- volume.stats [,COL_VOLUME ]
54- vols <- vols [which(sapply(1 : length(volume.chars ), function (v ) length(intersect(chars , volume.chars [[v ]]))> 0 ))]
55- vols <- vols [- (1 : 11 )] # remove earlier volumes to save some space
56- vols <- vols [- length(vols )] # same with latter volumes
57- vols <- vols [- which(grepl(" J" , vols , fixed = TRUE ))] # remove Young Thorgal volumes
58- vols.idx <- match(vols , volume.stats [,COL_VOLUME ])
59-
60- # read volume stats
61- stats <- list ()
62- for (v in 1 : nrow(volume.stats ))
63- { table.file <- get.path.stat.table(object = " nodes" , mode = " scenes" , net.type = " static" , weights = " duration" , vol = volume.stats [v ,COL_VOLUME ], filtered = filt.txt )
64- tt <- as.matrix(read.csv(table.file , header = TRUE , check.names = FALSE , row.names = 1 ))
65- idx <- match(chars ,rownames(tt ))
66- if (v == 1 )
67- { for (i in 1 : length(chars ))
68- { if (! is.na(idx [i ]))
69- stats [[chars [i ]]] <- tt [idx [i ],]
70- else
71- stats [[chars [i ]]] <- rep(NA ,ncol(tt ))
72- }
73- }
74- else
75- { for (i in 1 : length(chars ))
76- { if (! is.na(idx [i ]))
77- stats [[chars [i ]]] <- cbind(stats [[chars [i ]]], tt [idx [i ],])
78- else
79- stats [[chars [i ]]] <- cbind(stats [[chars [i ]]], rep(NA ,ncol(tt )))
45+ tlog(2 ," Loop by unfiltered/filtered net" )
46+ for (filt.txt in c(" unfiltered" ," filtered" ))
47+ { tlog(3 ," Processing the " ,filt.txt ," network" )
48+
49+ tlog(4 ," Loop by order" )
50+ for (ch.order in c(" publication" ," story" ))
51+ { tlog(5 ," Processing order\" " ,ch.order ," \" " )
52+
53+ # # vols <- c(
54+ # # "28", "29",
55+ # # "30", "31", "32",#"K1",
56+ # # "33", #"L1", "K2",
57+ # # "K3", #"L2", "J1", "L3",
58+ # # "K4", "34", #"J2","L4",
59+ # # "K5", #"L5", "J3",
60+ # # "K6", #"J4","L6",
61+ # # "35"
62+ # # )
63+ # vols <- volume.stats[,COL_VOLUME]
64+ # vols <- vols[which(sapply(1:length(volume.chars), function(v) length(intersect(chars, volume.chars[[v]]))>0))]
65+ # vols <- vols[-(1:11)] # remove earlier volumes to save some space
66+ # vols <- vols[-length(vols)] # same with latter volumes
67+ # vols <- vols[-which(grepl("J", vols, fixed=TRUE))] # remove Young Thorgal volumes
68+ # vols.idx <- match(vols, volume.stats[,COL_VOLUME])
69+ if (ch.order == " publication" )
70+ vols <- volume.stats [,COL_VOLUME ]
71+ else
72+ vols <- volume.stats [order(volume.stats [,COL_RANK ]),COL_VOLUME ]
73+ vols.idx <- match(vols , volume.stats [,COL_VOLUME ])
74+
75+ # read volume stats
76+ tlog(6 ," Reading volume stats" )
77+ ws <- c(" none" , " duration" , " occurrences" )
78+ ss <- list ()
79+ for (w in ws )
80+ { tlog(7 ," For weight \" " ,w ," \" " )
81+ stats <- list ()
82+ for (v in 1 : nrow(volume.stats ))
83+ { table.file <- get.path.stat.table(object = " nodes" , mode = " scenes" , net.type = " static" , weights = w , vol = paste0(v ," _" ,volume.stats [v ,COL_VOLUME ]), filtered = filt.txt )
84+ tlog(8 ," Reading table \" " ,table.file ," \" " )
85+ tt <- as.matrix(read.csv(table.file , header = TRUE , check.names = FALSE , row.names = 1 ))
86+ idx <- match(chars ,rownames(tt ))
87+ if (v == 1 )
88+ { for (i in 1 : length(chars ))
89+ { if (! is.na(idx [i ]))
90+ stats [[chars [i ]]] <- tt [idx [i ],]
91+ else
92+ stats [[chars [i ]]] <- rep(NA ,ncol(tt ))
93+ }
94+ }
95+ else
96+ { for (i in 1 : length(chars ))
97+ { if (! is.na(idx [i ]))
98+ stats [[chars [i ]]] <- cbind(stats [[chars [i ]]], tt [idx [i ],])
99+ else
100+ stats [[chars [i ]]] <- cbind(stats [[chars [i ]]], rep(NA ,ncol(tt )))
101+ }
102+ }
103+ }
104+ ss [[w ]] <- stats
80105 }
81- }
82- }
83-
84- # select measure
85- meass <- c(MEAS_DEGREE , MEAS_BETWEENNESS , MEAS_CLOSENESS , MEAS_EIGENCNTR , MEAS_STRENGTH )
86- meas <- meass [5 ]
87- w.name <- if (meas == MEAS_STRENGTH ) " duration" else NA
88106
89- # get values
90- vals <- c(stats [[1 ]][meas ,vols.idx ], stats [[2 ]][meas ,vols.idx ])
91- vals <- vals [! is.na(vals )]
92-
93- # create the plot
94- plot.file <- get.path.stats.topo(net.type = " static" , mode = " scenes" , meas.name = meas , vol = TRUE , filtered = filt.txt , weights = w.name , suf = paste0(" evolution_" ,paste0(chars.short ,collapse = " --" )))
95- tlog(6 , " Plotting in file \" " ,plot.file ," \" " )
96- for (fformat in PLOT_FORMAT )
97- { if (fformat == PLOT_FORMAT_PDF )
98- pdf(file = paste0(plot.file ,PLOT_FORMAT_PDF ), bg = " white" , width = 15 , height = 5 )
99- else if (fformat == PLOT_FORMAT_PNG )
100- png(filename = paste0(plot.file ,PLOT_FORMAT_PNG ), width = 2400 , height = 800 , units = " px" , pointsize = 20 , bg = " white" )
101- par(mar = c(4 ,4 ,0 ,0 )+ 0.1 ) # remove the title space Bottom Left Top Right
102- # init empty plot
103- plot(
104- NULL ,
105- xlim = c(1 ,length(vols )), ylim = range(vals ),
106- xlab = " Volume" , ylab = NODE_MEASURES [[meas ]]$ cname ,
107- xaxt = " n"
108- )
109- axis(1 ,at = 1 : length(vols ), labels = vols , cex.axis = 0.75 )
110- # add mean value
111- for (i in 1 : length(chars ))
112- abline(h = mean(stats [[i ]][meas ,]), lty = 2 , col = pal [i ])
113- # add lines
114- for (i in 1 : length(chars ))
115- { lines(
116- x = 1 : length(vols ), y = stats [[i ]][meas ,vols.idx ],
117- col = pal [i ]
118- )
107+ # select measure
108+ tlog(6 ," Looping over measures" )
109+ for (meas in meass )
110+ { tlog(7 ," Processing measure " ,meas )
111+ w.names <- if (meas == MEAS_STRENGTH ) c(" duration" ," occurrences" ) else " none"
112+
113+ tlog(8 ," Looping over weights" )
114+ for (w.name in w.names )
115+ { tlog(9 ," Processing weight " ,w.name )
116+ stats <- ss [[w.name ]]
117+
118+ # get values
119+ vals <- c(stats [[1 ]][meas ,vols.idx ], stats [[2 ]][meas ,vols.idx ])
120+ vals <- vals [! is.na(vals )]
121+
122+ # create the plot
123+ plot.file <- get.path.stats.topo(net.type = " static" , mode = " scenes" , meas.name = meas , vol = TRUE , filtered = filt.txt , weights = w.name , suf = paste0(" evolution-" ,ch.order ," _" ,paste0(chars.short ,collapse = " --" )))
124+ tlog(10 , " Plotting in file \" " ,plot.file ," \" " )
125+ for (fformat in PLOT_FORMAT )
126+ { if (fformat == PLOT_FORMAT_PDF )
127+ pdf(file = paste0(plot.file ,PLOT_FORMAT_PDF ), bg = " white" , width = 15 , height = 5 )
128+ else if (fformat == PLOT_FORMAT_PNG )
129+ png(filename = paste0(plot.file ,PLOT_FORMAT_PNG ), width = 2400 , height = 800 , units = " px" , pointsize = 20 , bg = " white" )
130+ par(mar = c(4 ,4 ,0 ,0 )+ 0.1 ) # remove the title space Bottom Left Top Right
131+ # init empty plot
132+ plot(
133+ NULL ,
134+ xlim = c(1 ,length(vols )), ylim = range(vals ),
135+ xlab = " Volume" , ylab = NODE_MEASURES [[meas ]]$ cname ,
136+ xaxt = " n"
137+ )
138+ axis(1 ,at = 1 : length(vols ), labels = vols , cex.axis = 0.75 )
139+ # add mean value
140+ for (i in 1 : length(chars ))
141+ abline(h = mean(stats [[i ]][meas ,]), lty = 2 , col = pal [i ])
142+ # add lines
143+ for (i in 1 : length(chars ))
144+ { lines(
145+ x = 1 : length(vols ), y = stats [[i ]][meas ,vols.idx ],
146+ col = pal [i ]
147+ )
148+ }
149+ # legend
150+ legend(
151+ title = " Characters" ,
152+ x = " topleft" ,
153+ fill = pal ,
154+ legend = chars.short
155+ )
156+ # close file
157+ dev.off()
158+ }
159+ }
119160 }
120- # legend
121- legend(
122- title = " Characters" ,
123- x = " topleft" ,
124- fill = pal ,
125- legend = chars.short
126- )
127- # close file
128- dev.off()
161+ }
129162}
130163
131164
0 commit comments