forked from NOAA-EDAB/RpathQNM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore_sp_fig.R
More file actions
170 lines (130 loc) · 5.59 KB
/
Core_sp_fig.R
File metadata and controls
170 lines (130 loc) · 5.59 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
library(reshape2)
library(ggplot2)
library(gridExtra)
setwd("~/QNM_WG/Comparison MS")
dat<-read.csv("core_species.csv", sep=",")
head(dat)
dat<- subset(dat, typenode=="core")
dat_long <- melt(dat,
# ID variables - all the variables to keep but not split apart on
id.vars=c("system", "scen","node"),
# The source columns
measure.vars=c("catbbn", "catfcm", "catqnm" ),
# Name of the destination column that will identify the original
# column that the measurement came from
variable.name="model",
value.name="response"
)
dat_sign <- melt(dat,
# ID variables - all the variables to keep but not split apart on
id.vars=c("system", "scen","node"),
# The source columns
measure.vars=c("bbn", "fcm", "qnm" ),
# Name of the destination column that will identify the original
# column that the measurement came from
variable.name="model",
value.name="response"
)
dat_sign$sign<- "positive"
dat_sign$sign[dat_sign$response< 0] <- "negative"
dat_sign$sign[dat_sign$response==0] <- "zero"
dat_long$sign<-dat_sign$sign
# Order the factor levels QNM, BBN, FCM
# Order the factor levels weak, moderate, strong
dat_long$response<-factor(dat_long$response, levels=c("weak", "moderate", "strong"))
dat_long$model<-factor(dat_long$model, levels=c("catqnm", "catfcm", "catbbn"))
dat_long$system<-factor(dat_long$system, levels=c("PI", "GB", "BAR"))
dat_long$scen<-factor(dat_long$scen, levels=c("t", "w", "tw"))
# Fill symbols if strong or moderate
dat_long$fill<- "weak"
dat_long$fill[dat_long$response!="weak" & dat_long$sign=="negative"]<- "negstrong"
dat_long$fill[dat_long$response!="weak" & dat_long$sign=="positive"]<- "posstrong"
########################
# Plot up responses as bubble plots
dat_pi<- subset(dat_long, system=="PI")
dat_pi$node<-factor(dat_pi$node, levels=c( "HalA","PC","RKCA","BKCA"))
p1<- ggplot(dat_pi)+
geom_point(aes(y=node, x=model,cex=response,
pch=sign, color=sign, fill=fill)) +
scale_color_manual( values=c("lightblue","orangered","grey"))+
scale_shape_manual(values=c(25,24,22)) +
scale_fill_manual(values=c("lightblue","orangered","white")) +
facet_grid(~scen) +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
legend.position = "none",
strip.background = element_blank()) +
scale_y_discrete(labels=c( "BKCA" = "BKC-A",
"RKCA" = "RKC-A",
"PC" = "Pacific cod",
"HalA" = "Halibut-A"))
dat_gb<-subset(dat_long, system=="GB")
dat_gb$node<-factor(dat_gb$node, levels=c( "Seafood","HabitatSeafloorDemersal","Forage Fish", "Groundfish"))
p2<- ggplot(dat_gb)+
geom_point(aes(y=node, x=model,cex=response,
pch=sign, color=sign, fill=fill)) +
scale_color_manual( values=c("lightblue","orangered","grey"))+
scale_shape_manual(values=c(25,24,22)) +
scale_fill_manual(values=c("lightblue","orangered","white")) +
facet_grid(~scen) +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
legend.position = "none" ,
strip.background = element_blank(),
strip.text.x = element_blank()) +
scale_y_discrete(labels=c( "Forage Fish" = "Forage fish",
"HabitatSeafloorDemersal" = "HSD"))
dat_bar<-subset(dat_long, system=="BAR")
dat_bar$node<-factor(dat_bar$node, levels=c( "Wetlands","Recreation","Habitable Land", "Fish"))
p3<- ggplot(dat_bar)+
geom_point(aes(y=node, x=model,cex=response,
pch=sign, color=sign, fill=fill)) +
scale_color_manual( values=c("lightblue","orangered","grey"))+
scale_shape_manual(values=c(25,24,22)) +
scale_fill_manual(values=c("lightblue","orangered","white")) +
facet_grid(~scen) +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.title.y=element_blank(),
legend.position = "none",
strip.background = element_blank(),
strip.text.x = element_blank()) +
scale_x_discrete(labels=c("catqnm" = "QNM", "catbbn" = "BBN",
"catfcm" = "FCM")) +
scale_y_discrete(labels=c( "Habitable Land" = "HL"))
grid.arrange(p1, p2, p3, ncol=1)
library(gtable)
library(grid)
g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
g3 <- ggplotGrob(p3)
g <- rbind(g1,g2, g3, size = "first")
g$widths <- unit.pmax(g1$widths, g2$widths, g3$widths)
grid.newpage()
grid.draw(g)
#ggsave(filename="core_nodes_REV.pdf", width = 15, height = 15, units = "cm", dpi=300)
#ggsave not working for some reason
grid.newpage()
pdf("core_nodes_REV.pdf", width = 4, height = 5)
grid.draw(g)
dev.off()
# To edit the image further:
# 1. Export saved pdf into adobe acrobat
# 2. Print and so now we have larger margins
# 3. Export to power point. Add in additional labels, legends that you want.
# 4. Save as pdf.