-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanelcode
243 lines (187 loc) · 7.39 KB
/
panelcode
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
###########################################################################
#########This script contains code and examples #####################
#########for making scientific quality figures. #####################
###########################################################################
#read in example dataset
setwd('/Users/lmccullo/Google Drive/LM_root_paper')
ak<- read.csv("ViPER_roots_2015_LM.csv")
akk<- read.csv("ViPER_Root_Agg.csv")
t<- read.csv("agg_temp_15cm.csv")
tt<- read.csv("agg_temp_10cm.csv")
#######################################################
######## Make a multipanel figure #####################
#######################################################
#this code makes a multipanel figure in a jpeg
#that will have manuscript quality label sizes.
#it uses the example dataset to generate the figure
#but it can be changed to any type of data.
#1. specify the directory where you will save your plots
plotDir <- '/Users/lmccullo/Google Drive/Alaska2015/Figures'
#2. specify the number of panels you will need in your plot
pN <- 12
#3. specify how many columns of panes you want
pC <- 4
#4. specify width and height of the panels
#these numbers will depend on how big you make your jpeg
#if they are too big of a size for the jpeg, you will get
#a figure region too big
wd <- 100
hd <- 35
#5. Declare the boundries of each plot limits. This way
#you can readily alter the plot limits without having
#to change anything by hand
#I am going to make a panel of relative humidity and
#temperature across each hourfor each of my sites.
#Each site has a different time period.
#I will stack the graphs so that each column in the
#panel is a site since it shares the same values on
#the x axis.
#x axis limits
#axis soil c:n ratio
xl1 <- 0
xh1 <- 50
#x axis soil temperature to 10 cm
xl2 <- -4
xh2 <- 6
#%moss cover
xl3 <- 0
xh3 <- 55
#organic soil moisture
xl4 <- 110
xh4 <- 900
#Live to dead ratio
ylR <- 0
yhR <- 33
#axis label sequences
ysT <- seq(0,33, by=3)
ysR <- seq(0,33, by=3)
xs1 <- seq(0,50,by=5)
xs2 <- seq(-4,6,by=1)
xs3 <-seq(0,55,by=5)
xs4 <-seq(110,900, by = 100)
#character expansions
#cex for plot symbols
cP <- 8
#for y axis
cAy <- 5
#for axis labesl
clabel <- 6
#for x axis
cAx <- 4
#colors for plot symbols
col1 <- "royalblue3"
col2 <- "tomato3"
#line thickness
lw <- 3
#panel letter size and location
#cex for letter label
cl <- 8
#offset from panels
l.offs <- .1
l.offT <- 1
l.offR <-.05
#6. Start generating the plot
#this command will start plotting to file, and anything after it will go to your file.
#It can only be ended with the dev.off() function.
#the plot will be generated into the directory plotDir indicated above
jpeg(paste0(plotDir, "//multipanel1.jpg"), width=100000, height=100000, units="px", quality=100)
####################################################
############ jpeg #######################
####################################################
#jpeg(file.name and path, width=width of file, height=height of file,
# units="px" indicated pixel units, quality=100 (lower numbers will produce lower quality))
# 7. specify the panel layout
#the layout is based on the number of panels declared above (pn),
#the number of columns specified above (pc), and the width and height
#of each panel (wd, hd respectively) that was specified above
layout(matrix(seq(1,pN), byrow=FALSE, ncol=pC), width=rep(lcm(wd),pN), height=rep(lcm(hd),pN))
####################################################
############ layout #######################
####################################################
#layout(matrix that is structured to the layout of the panels that contains the plot
#order for each panel, width=widths for each panel, height=heights for each panel)
# 8. start making the plot for panel 1: high density Temp
#8.A. Specify that there should be no margins to the plot
par(mai=c(0,0,0,0))
#8.B. Make an empty plot with the proper limits above
# all points, labels, and axes will be added in seperately.
plot(c(0,1),c(0,1), type="n", xlim=c(xl1,xh1), ylim=c(ylT,yhT), axes=FALSE, xlab=" ",
ylab=" ", xaxs="i", yaxs="i")
#8. C. add the points that we want to plot
points(tt$soilc.n,tt$fine.dead.live, type="b",
col=col1, lwd=lw, cex=cP, pch=19)
#8. D. make axis for y axis
axis(2, ysT, cex.axis=cAy, las=2, lwd.ticks=3)
#8. E. add a letter to label the panel
text(xl1+l.offs,yhT-l.offT, "A", cex=cl)
#8. F. label the y axis
mtext("Dead:Live biomass", side=2, cex=clabel, line=15)
#8. G. make a box around the plot
box(which="plot")
#8. H. label the site
mtext("Soil C:N", side=1, cex=clabel, line=5)
# 9. start making the plot for panel 2: high density RH
#9.A. Specify that there should be no margins to the plot
par(mai=c(0,0,0,0))
#9.B. Make an empty plot with the proper limits above
# all points, labels, and axes will be added in seperately.
plot(c(0,1),c(0,1), type="n", xlim=c(xl2,xh2), ylim=c(ylT,yhT), axes=FALSE, xlab=" ",
ylab=" ", xaxs="i", yaxs="i")
#9. C. add the points that we want to plot
points(tt$temp,tt$fine.dead.live, type="b",
col=col1, lwd=lw, cex=cP, pch=19)
#9. D. make axis for y axis
axis(2, ysR, cex.axis=cAy, las=2, lwd.ticks=3)
#9. E. add a letter to label the panel
text(xl1+l.offs,yhR-l.offR, "B", cex=cl)
#9. F. label the y axis
mtext("Soil Temperature to 10 cm (C)", side=2, cex=clabel, line=15)
#9. G. make a box around the plot
box(which="plot")
#9. H. make labels for the xaxis
#x axis labels don't get offset from the axis as well in jpeg file set up.
#they will be set up a little differently
#first add axis ticks
axis(1, xs1, rep(" ", length(xs1)), lwd.ticks=3)
mtext(xs1, at=xs1, side=1, line=4, cex=cAx)
#9. I. add an outer label for both bottom panels since they have the same measure
mtext("Ratio of Fine Dead to Live biomass", side=1, outer=TRUE, line=-7, cex=clabel)
# 10. start making the plot for panel 3: low density Temp
#10.A. Specify that there should be no margins to the plot
par(mai=c(0,0,0,0))
#10.B. Make an empty plot with the proper limits above
# all points, labels, and axes will be added in seperately.
plot(c(0,1),c(0,1), type="n", xlim=c(xl2,xh2), ylim=c(ylT,yhT), axes=FALSE, xlab=" ",
ylab=" ", xaxs="i", yaxs="i")
#10. C. add the points that we want to plot
points(tt$m.cov, tt$fine.dead.live, type="b",
col=col2, lwd=lw, cex=cP, pch=19)
#10. D. add a letter to label the panel
text(xl2+l.offs,yhT-l.offT, "C", cex=cl)
#10. E. make a box around the plot
box(which="plot")
#10. F. label the site
mtext("%Moss Cover", side=3, cex=clabel, line=5)
# 11. start making the plot for panel 2: high density RH
#11.A. Specify that there should be no margins to the plot
par(mai=c(0,0,0,0))
#11.B. Make an empty plot with the proper limits above
# all points, labels, and axes will be added in seperately.
plot(c(0,1),c(0,1), type="n", xlim=c(xl2,xh2), ylim=c(ylR,yhR), axes=FALSE, xlab=" ",
ylab=" ", xaxs="i", yaxs="i")
#11. C. add the points that we want to plot
points(tt$org.moisture, tt$fine.dead.live, type="b",
col=col2, lwd=lw, cex=cP, pch=19)
#11. D. add a letter to label the panel
text(xl2+l.offs,yhR-l.offR, "D", cex=cl)
#11. E. make a box around the plot
box(which="plot")
#11. F. make labels for the xaxis
#x axis labels don't get offset from the axis as well in jpeg file set up.
#they will be set up a little differently
#first add axis ticks
axis(1, xs2, rep(" ", length(xs2)), lwd.ticks=3)
mtext(xs2, at=xs2, side=1, line=4, cex=cAx)
plot
#12. turn off plot
dev.off()