-
Notifications
You must be signed in to change notification settings - Fork 0
/
dissanalysis_f.R
80 lines (69 loc) · 3.47 KB
/
dissanalysis_f.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
### FUNCTIONS FILE FOR PIRATE DISSEMINATION ANALYSIS
### list of functions and last update :
### - media_count (11/06/2015) : sum of impacted people for each impact level
### - public_count (11/06/2015) : sum of impacted people for each dissemination level
### - summaryplot_f (10/06/2015)[INCOMPLETE] : plot all graph for selected partner as one A4 with title
##count media (impact levels)
media_count<-function (nodouble){
IMPACTS <- rbind(by(nodouble[,8],nodouble[,2],sum))
IMPACTS<-t(IMPACTS)
IMPACTS <- as.data.frame(IMPACTS)
names(IMPACTS)<-"people"
impact <-rownames(IMPACTS)
IMPACTS <- cbind(impact,IMPACTS)
IMPACTS <- IMPACTS[order(IMPACTS$people),]
IMPACTS$impact<-factor(IMPACTS$impact, levels=IMPACTS$impact[order(IMPACTS$people)])
return(IMPACTS)
}
##count publics (dissemination levels)
public_count<-function (nodouble){
TARGET<-rbind(by(nodouble[,8], nodouble[,7], sum))
TARGET<-t(TARGET)
TARGET<-as.data.frame(TARGET)
names(TARGET)<-"people"
target<-rownames(TARGET)
TARGET<-cbind(target,TARGET)
TARGET<-TARGET[order(TARGET$people),]
TARGET$target<-factor(TARGET$target, levels=TARGET$target[order(TARGET$people)])
return(TARGET)
}
## summaryplot function to plot side by side bar charts and table of numeric values.
# All charts have the same scale to allow easy comparison.
# zoom can be changed to adapt for each graph, Targeted remains global to allow comparison with the total of the consortium
# use 3000 for zoom for optimal view with interim diss.
summaryplot_f<- function(TARG,IMP,TARG_p, IMP_p, Targeted, zoom=3000, mainT="PIRATE Dissemination", subT="")
{
table_limit<-Targeted-100000
table_zero<-(Targeted/2)+10000
alpha_g<-0.2
TARGETplot_overall <- ggplot(data=TARG, aes(x=target, y=people))+
geom_bar(stat="identity", fill="black")+
geom_bar(data=TARG, aes(x=target, y=total_target),stat="identity", alpha=alpha_g) +
labs(x="",y="", title="People/dissemination levels")+
scale_y_continuous(limits=c(0, table_limit), breaks=seq(0,Targeted,250000), labels=comma) +
theme_bw()+
annotation_custom(tableGrob(TARG_p[rev(rownames(TARG_p)),], gpar.coretext = gpar(fontsize = 11), show.rownames=FALSE), xmin=1.5, xmax=4, ymin=table_zero, ymax=table_limit-50000)+
coord_flip()
IMPACTSplot_overall<-ggplot(data=IMP, aes(x=impact , y=people))+
geom_bar(stat="identity", fill="black") +
geom_bar(data=IMP, aes(x=impact, y=total_impact), stat="identity", alpha=alpha_g) +
labs(x="",y="", title="People/impact levels") +
scale_y_continuous(limits=c(0, table_limit), breaks=seq(0,Targeted,100000), labels=comma) +
theme_bw()+
annotation_custom(tableGrob(IMP_p[rev(rownames(IMP_p)),], gpar.coretext = gpar(fontsize = 11), show.rownames=FALSE), xmin=2, xmax=5, ymin=table_zero, ymax=table_limit-50000)+
coord_flip()
TARGETplot_zoom <- ggplot(TARG, aes(x=target, y=people))+
geom_bar(stat="identity", fill="grey") +
geom_bar(data=TARG, aes(x=target, y=total_target),stat="identity", alpha=alpha_g) +
labs(x="",y="")+
theme_bw()+
coord_flip(ylim=c(0, zoom))
IMPACTSplot_zoom <-ggplot(IMP, aes(x=impact , y=people))+
geom_bar(stat="identity", fill="grey") +
geom_bar(data=IMP, aes(x=impact, y=total_impact), stat="identity", alpha=alpha_g) +
labs(x="",y="") +
theme_bw()+
coord_flip(ylim=c(0, zoom))
summaryplot<-arrangeGrob(TARGETplot_overall, IMPACTSplot_overall, TARGETplot_zoom, IMPACTSplot_zoom, ncol=2, nrow=2, main=mainT, sub=subT)
return(summaryplot)
}