-
Notifications
You must be signed in to change notification settings - Fork 2
/
bar.R
executable file
·405 lines (379 loc) · 21.5 KB
/
bar.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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/env Rscript
args <- commandArgs()
scriptPath = strsplit(args[4], '=', fixed = T)[[1]][2]
scriptName = basename(scriptPath)
scriptDir = dirname(scriptPath)
args = args[-(1:5)]
source(paste0(scriptDir, '/common.R'))
usage = function(){
cat(paste0("Usage: ", scriptName))
cat(" -p=outputName.pdf <input.tsv
Option:
Common:
-p|pdf FILE The output figure in pdf[figure.pdf]
-w|width INT The figure width
-height INT The figure height
-m|main STR The main title
-mainS DOU The size of main title[22 for ggplot]
-x|xlab STR The xlab[]
-y|ylab STR The ylab
-xl|xlog INT Transform the X scale to INT base log
-yl|ylog INT Transform the Y scale to INT base log
-x1 INT The xlim start
-x2 INT The xlim end
-y1 INT The ylim start
-y2 INT The ylim end
-xLblS DOU The X-axis label size[20 for ggplot]
-xTxtS DOU The X-axis text size[18 for ggplot]
-xAngle [0,360] The angle of tick labels[0]
-vJust [0,1] The vertical justification of tick labels[0.5]
-yLblS DOU The Y-axis label size[20 for ggplot]
-yTxtS DOU The Y-axis text size[18 for ggplot]
-ng|noGgplot Draw figure in the style of R base rather than ggplot
-ho|horizontal DOU Draw a horizontal line
-h|help Show help
ggplot specific:
-st|stat STR The stat ([identity], bin, ...)
-b|binWidth DOU The bin width[1/30 of the range of the data]
-barWidth DOU The width of bar[0.9]
-pos|position STR The position of multiple bars ([stack], dodge, fill, ...)
-anno Annotate Y values on top of bar
-errBarMinV STR The column name of ymin of errorBar (V3, V4,...)
-errBarMaxV STR The column name of ymax of errorBar (V3, V4,...)
-errBarWidth DOU The error bar width[0.9]
-a|alpha DOU The alpha of bar body
-alphaV STR The column name to apply alpha (V3, V4, ...)
-alphaT STR The title of alpha legend[Alpha]
-alphaTP POS The title position of alpha legend[horizontal: top, vertical:right]
-alphaLP POS The label position of alpha legend[horizontal: top, vertical:right]
-alphaD STR The direction of alpha legend (horizontal, vertical)
-c|color STR The color of bar boundary
-colorV STR The column name to apply color (V3, V4,...)
-colorC Continuous color mapping
-colorT STR The title of color legend[Color]
-colorTP POS The title position of color legend[horizontal: top, vertical:right]
-colorLP POS The label position of color legend[horizontal: top, vertical:right]
-colorD STR The direction of color legend (horizontal, vertical)
-f|fill STR The color of bar body
-fillV STR The column name to apply fill (V3, V4,...)
-fillT STR The title of fill legend[Fill]
-fillTP POS The title position of fill legend[horizontal: top, vertical:right]
-fillLP POS The label position of fill legend[horizontal: top, vertical:right]
-fillD STR The direction of fill legend (horizontal, vertical)
-l|linetype INT The line type
-linetypeV STR The column name to apply linetype (V3, V4,...)
-linetypeT STR The title of linetype legend[Line Type]
-linetypeTP POS The title position of linetype legend[horizontal: top, vertical:right]
-linetypeLP POS The label position of linetype legend[horizontal: top, vertical:right]
-linetypeD STR The direction of linetype legend (horizontal, vertical)
-s|size DOU The size of bar boundary
-sizeV STR The column name to apply size (V3, V4,...)
-sizeT STR The title of size legend[Size]
-sizeTP POS The title position of size legend[horizontal: top, vertical:right]
-sizeLP POS The label position of size legend[horizontal: top, vertical:right]
-sizeD STR The direction of size legend (horizontal, vertical)
-weight DOU The weight of bar
-weightV STR The column name to apply weight (V3, V4,...)
-weightT STR The title of weight legend[weight]
-weightTP POS The title position of weight legend[horizontal: top, vertical:right]
-weightLP POS The label position of weight legend[horizontal: top, vertical:right]
-weightD STR The direction of weight legend (horizontal, vertical)
-noGuide Don't show the legend guide
-lgPos POS The legend position[horizontal: top, vertical:right]
-lgPosX [0,1] The legend relative postion on X
-lgPosY [0,1] The legend relative postion on Y
-lgTtlS INT The legend title size[22]
-lgTxtS INT The legend text size[20]
-lgBox STR The legend box style (horizontal, vertical)
-fp|flip Flip the bar to horizontal
-facet STR The facet type (facet_wrap, facet_grid)
-facetM STR The facet model (eg: '~V3', '. ~ V3', 'V3 ~ .', 'V3 ~ V4', '. ~ V3 + V4', ...)
-facetScl STR The axis scale in each facet ([fixed], free, free_x or free_y)
-facetCol INT ncol for facet_wrap
-facetRow INT nrow for facet_wrap
-xPer Show X label in percentage
-yPer Show Y label in percentage
-xComma Show X label number with comma separator
-yComma Show Y label number with comma separator
-axisRatio DOU The fixed aspect ratio between y and x units
-annoTxt STRs The comma-separated texts to be annotated
-annoTxtX INTs The comma-separated X positions of text
-annoTxtY INTs The comma-separated Y positions of text
-annoTxtS DOU The annotated text size[5]
Skill:
Legend title of alpha, color, etc can be set as the same to merge their guides
")
q(save = 'no')
}
stat = 'identity'
alphaT = 'Alpha'
colorT = 'Color'
fillT = 'Fill'
linetypeT = 'Line Type'
sizeT = 'Size'
weightT = 'Weight'
lgTtlS = 22
lgTxtS = 20
showGuide = TRUE
myPdf = 'figure.pdf'
mainS = 22
xLab=''
xLblS = 20
xTxtS = 18
xAngle = 0
vJust = 0.5
yLblS = 20
yTxtS = 18
errBarWidth = 0.9
annoTxtS = 5
if(length(args) >= 1){
for(i in 1:length(args)){
arg = args[i]
tmp = parseArgAsNum(arg, 'ho(rizontal)?', 'ho'); if(!is.null(tmp)) horizontal = tmp
tmp = parseArgAsNum(arg, 'barWidth', 'barWidth'); if(!is.null(tmp)) barWidth = tmp
tmp = parseArg(arg, 'st(at)?', 'st'); if(!is.null(tmp)) stat = tmp
tmp = parseArgAsNum(arg, 'b(inWidth)?', 'b'); if(!is.null(tmp)) binWidth = tmp
tmp = parseArg(arg, 'pos(ition)?', 'pos'); if(!is.null(tmp)) position = tmp
if(arg == '-anno') anno = TRUE
tmp = parseArgAsNum(arg, 'a(lpha)?', 'a'); if(!is.null(tmp)) myAlpha = tmp
tmp = parseArg(arg, 'alphaV', 'alphaV'); if(!is.null(tmp)) alphaV = tmp
tmp = parseArg(arg, 'alphaT', 'alphaT'); if(!is.null(tmp)) alphaT = tmp
tmp = parseArg(arg, 'alphaTP', 'alphaTP'); if(!is.null(tmp)) alphaTP = tmp
tmp = parseArg(arg, 'alphaLP', 'alphaLP'); if(!is.null(tmp)) alphaLP = tmp
tmp = parseArg(arg, 'alphaD', 'alphaD'); if(!is.null(tmp)) alphaD = tmp
tmp = parseArg(arg, 'c(olor)?', 'c'); if(!is.null(tmp)) color = tmp
tmp = parseArg(arg, 'colorV', 'colorV'); if(!is.null(tmp)) colorV = tmp
if(arg == '-colorC') colorC = TRUE
tmp = parseArg(arg, 'colorT', 'colorT'); if(!is.null(tmp)) colorT = tmp
tmp = parseArg(arg, 'colorTP', 'colorTP'); if(!is.null(tmp)) colorTP = tmp
tmp = parseArg(arg, 'colorLP', 'colorLP'); if(!is.null(tmp)) colorLP = tmp
tmp = parseArg(arg, 'colorD', 'colorD'); if(!is.null(tmp)) colorD = tmp
tmp = parseArg(arg, 'f(ill)?', 'f'); if(!is.null(tmp)) fill = tmp
tmp = parseArg(arg, 'fillV', 'fillV'); if(!is.null(tmp)) fillV = tmp
tmp = parseArg(arg, 'fillT', 'fillT'); if(!is.null(tmp)) fillT = tmp
tmp = parseArg(arg, 'fillTP', 'fillTP'); if(!is.null(tmp)) fillTP = tmp
tmp = parseArg(arg, 'fillLP', 'fillLP'); if(!is.null(tmp)) fillLP = tmp
tmp = parseArg(arg, 'fillD', 'fillD'); if(!is.null(tmp)) fillD = tmp
tmp = parseArgAsNum(arg, 'l(inetype)?', 'l'); if(!is.null(tmp)) linetype = tmp
tmp = parseArg(arg, 'linetypeV', 'linetypeV'); if(!is.null(tmp)) linetypeV = tmp
tmp = parseArg(arg, 'linetypeT', 'linetypeT'); if(!is.null(tmp)) linetypeT = tmp
tmp = parseArg(arg, 'linetypeTP', 'linetypeTP'); if(!is.null(tmp)) linetypeTP = tmp
tmp = parseArg(arg, 'linetypeLP', 'linetypeLP'); if(!is.null(tmp)) linetypeLP = tmp
tmp = parseArg(arg, 'linetypeD', 'linetypeD'); if(!is.null(tmp)) linetypeD = tmp
tmp = parseArgAsNum(arg, 's(ize)?', 's'); if(!is.null(tmp)) size = tmp
tmp = parseArg(arg, 'sizeV', 'sizeV'); if(!is.null(tmp)) sizeV = tmp
tmp = parseArg(arg, 'sizeT', 'sizeT'); if(!is.null(tmp)) sizeT = tmp
tmp = parseArg(arg, 'sizeTP', 'sizeTP'); if(!is.null(tmp)) sizeTP = tmp
tmp = parseArg(arg, 'sizeLP', 'sizeLP'); if(!is.null(tmp)) sizeLP = tmp
tmp = parseArg(arg, 'sizeD', 'sizeD'); if(!is.null(tmp)) sizeD = tmp
tmp = parseArgAsNum(arg, 'weight', 'weight'); if(!is.null(tmp)) weight = tmp
tmp = parseArg(arg, 'weightV', 'weightV'); if(!is.null(tmp)) weightV = tmp
tmp = parseArg(arg, 'weightT', 'weightT'); if(!is.null(tmp)) weightT = tmp
tmp = parseArg(arg, 'weightTP', 'weightTP'); if(!is.null(tmp)) weightTP = tmp
tmp = parseArg(arg, 'weightLP', 'weightLP'); if(!is.null(tmp)) weightLP = tmp
tmp = parseArg(arg, 'weightD', 'weightD'); if(!is.null(tmp)) weightD = tmp
if(arg == '-noGuide') showGuide = FALSE
tmp = parseArg(arg, 'lgPos', 'lgPos'); if(!is.null(tmp)) lgPos = tmp
tmp = parseArgAsNum(arg, 'lgPosX', 'lgPosX'); if(!is.null(tmp)) lgPosX = tmp
tmp = parseArgAsNum(arg, 'lgPosY', 'lgPosY'); if(!is.null(tmp)) lgPosY = tmp
tmp = parseArgAsNum(arg, 'lgTtlS', 'lgTtlS'); if(!is.null(tmp)) lgTtlS = tmp
tmp = parseArgAsNum(arg, 'lgTxtS', 'lgTxtS'); if(!is.null(tmp)) lgTxtS = tmp
tmp = parseArg(arg, 'lgBox', 'lgBox'); if(!is.null(tmp)) lgBox = tmp
if(arg == '-fp' || arg =='-flip') flip = TRUE
tmp = parseArg(arg, 'facet', 'facet'); if(!is.null(tmp)) myFacet = tmp
tmp = parseArg(arg, 'facetM', 'facetM'); if(!is.null(tmp)) facetM = tmp
tmp = parseArg(arg, 'facetScl', 'facetScl'); if(!is.null(tmp)) facetScl = tmp
tmp = parseArgAsNum(arg, 'facetCol', 'facetCol'); if(!is.null(tmp)) facetCol = tmp
tmp = parseArgAsNum(arg, 'facetRow', 'facetRow'); if(!is.null(tmp)) facetRow = tmp
if(arg == '-xPer') xPer = TRUE
if(arg == '-yPer') yPer = TRUE
if(arg == '-xComma') xComma = TRUE
if(arg == '-yComma') yComma = TRUE
tmp = parseArgAsNum(arg, 'axisRatio', 'axisRatio'); if(!is.null(tmp)) axisRatio = tmp
tmp = parseArg(arg, 'annoTxt', 'annoTxt'); if(!is.null(tmp)) annoTxt = tmp
tmp = parseArg(arg, 'annoTxtX', 'annoTxtX'); if(!is.null(tmp)) annoTxtX = tmp
tmp = parseArg(arg, 'annoTxtY', 'annoTxtY'); if(!is.null(tmp)) annoTxtY = tmp
tmp = parseArgAsNum(arg, 'annoTxtS', 'annoTxtS'); if(!is.null(tmp)) annoTxtS = tmp
if(arg == '-h' || arg == '-help') usage()
tmp = parseArg(arg, 'p(df)?', 'p'); if(!is.null(tmp)) myPdf = tmp
tmp = parseArgAsNum(arg, 'w(idth)?', 'w'); if(!is.null(tmp)) width = tmp
tmp = parseArgAsNum(arg, 'height', 'heigth'); if(!is.null(tmp)) height = tmp
if(arg == '-ng' || arg == '-noGgplot') noGgplot = TRUE
tmp = parseArgAsNum(arg, 'x1', 'x1'); if(!is.null(tmp)) x1 = tmp
tmp = parseArgAsNum(arg, 'x2', 'x2'); if(!is.null(tmp)) x2 = tmp
tmp = parseArgAsNum(arg, 'y1', 'y1'); if(!is.null(tmp)) y1 = tmp
tmp = parseArgAsNum(arg, 'y2', 'y2'); if(!is.null(tmp)) y2 = tmp
tmp = parseArgAsNum(arg, 'xl(og)?', 'xl'); if(!is.null(tmp)) xLog = tmp
tmp = parseArgAsNum(arg, 'yl(og)?', 'yl'); if(!is.null(tmp)) yLog = tmp
tmp = parseArg(arg, 'm(ain)?', 'm'); if(!is.null(tmp)) main = tmp
tmp = parseArgAsNum(arg, 'mainS', 'mainS'); if(!is.null(tmp)) mainS = tmp
tmp = parseArg(arg, 'x(lab)?', 'x'); if(!is.null(tmp)) xLab = tmp
tmp = parseArg(arg, 'y(lab)?', 'y'); if(!is.null(tmp)) yLab = tmp
tmp = parseArgAsNum(arg, 'xAngle', 'xAngle'); if(!is.null(tmp)) xAngle = tmp
tmp = parseArgAsNum(arg, 'vJust', 'vJust'); if(!is.null(tmp)) vJust = tmp
tmp = parseArgAsNum(arg, 'xLblS', 'xLblS'); if(!is.null(tmp)) xLblS = tmp
tmp = parseArgAsNum(arg, 'xTxtS', 'xTxtS'); if(!is.null(tmp)) xTxtS = tmp
tmp = parseArgAsNum(arg, 'yLblS', 'yLblS'); if(!is.null(tmp)) yLblS = tmp
tmp = parseArgAsNum(arg, 'yTxtS', 'yTxtS'); if(!is.null(tmp)) yTxtS = tmp
tmp = parseArg(arg, 'errBarMinV', 'errBarMinV'); if(!is.null(tmp)) errBarMinV = tmp
tmp = parseArg(arg, 'errBarMaxV', 'errBarMaxV'); if(!is.null(tmp)) errBarMaxV = tmp
tmp = parseArgAsNum(arg, 'errBarWidth', 'errBarWidth'); if(!is.null(tmp)) errBarWidth = tmp
}
}
sink(stderr())
cat('Check if the following variables are correct as expected:')
cat('\npdf\t'); if(exists('myPdf')) cat(myPdf)
cat('\nwidth\t'); if(exists('width')) cat(width)
cat('\nxAngle\t'); if(exists('xAngle')) cat(xAngle)
cat('\nnoGgplot\t'); if(exists('noGgplot')) cat(noGgplot)
cat('\n')
sink()
myCmd = 'pdf(myPdf'
if(exists('width')) myCmd = paste0(myCmd, ', width = width')
if(exists('height')) myCmd = paste0(myCmd, ', height = height')
myCmd = paste0(myCmd, ')')
eval(parse(text = myCmd))
data = read.delim(file('stdin'), header = F)
if(exists('noGgplot')){
myCmd = 'mp = barplot('
if(ncol(data) > 1){
myCmd = paste0(myCmd, 'data$V2, names.arg = data$V1')
}else{
myCmd = paste0(myCmd, 'data$V1')
}
if(exists('myMain')) myCmd = paste0(myCmd, ', main = myMain')
if(exists('myXlab')) myCmd = paste0(myCmd, ', xlab = myXlab')
if(exists('myYlab')) myCmd = paste0(myCmd, ', ylab = myYlab')
myCmd = paste0(myCmd, ')')
eval(parse(text = myCmd))
if(exists('anno')) text(mp, data[[2]], data[[2]])
}else{
library(ggplot2)
if(stat == 'identity'){
if(ncol(data) == 1){
data = cbind(data.frame(ID = paste0('ID', 1:nrow(data))), data)
p = ggplot(data, aes(x = factor(ID, levels = ID), y = V1))
}else{
p = ggplot(data, aes(x = factor(V1, levels = unique(V1)), y = V2))
}
}else{
p = ggplot(data, aes(x = V1))
}
if(exists('alphaV')){
p = p + aes_string(alpha = alphaV)
myCmd = 'p = p + guides(alpha = guide_legend(alphaT'
if(exists('alphaTP')) myCmd = paste0(myCmd, ', title.position = alphaTP')
if(exists('alphaLP')) myCmd = paste0(myCmd, ', label.position = alphaLP')
if(exists('alphaD')) myCmd = paste0(myCmd, ', direction = alphaD')
myCmd = paste0(myCmd, '))')
eval(parse(text = myCmd))
}
if(exists('colorV')){
if(exists('colorC')){
p = p + aes_string(color = colorV)
}else{
myCmd = paste0('p = p + aes(color = factor(', colorV, '))'); eval(parse(text = myCmd))
}
myCmd = 'p = p + guides(color = guide_legend(colorT'
if(exists('colorTP')) myCmd = paste0(myCmd, ', title.position = colorTP')
if(exists('colorLP')) myCmd = paste0(myCmd, ', label.position = colorLP')
if(exists('colorD')) myCmd = paste0(myCmd, ', direction = colorD')
myCmd = paste0(myCmd, '))')
eval(parse(text = myCmd))
}
if(exists('fillV')){
myCmd = paste0('p = p + aes(fill = factor(', fillV, '))'); eval(parse(text = myCmd))
myCmd = 'p = p + guides(fill = guide_legend(fillT'
if(exists('fillTP')) myCmd = paste0(myCmd, ', title.position = fillTP')
if(exists('fillLP')) myCmd = paste0(myCmd, ', label.position = fillLP')
if(exists('fillD')) myCmd = paste0(myCmd, ', direction = fillD')
myCmd = paste0(myCmd, '))')
eval(parse(text = myCmd))
}
if(exists('linetypeV')){
myCmd = paste0('p = p + aes(linetype = factor(', linetypeV, '))'); eval(parse(text = myCmd))
myCmd = 'p = p + guides(linetype = guide_legend(linetypeT'
if(exists('linetypeTP')) myCmd = paste0(myCmd, ', title.position = linetypeTP')
if(exists('linetypeLP')) myCmd = paste0(myCmd, ', label.position = linetypeLP')
if(exists('linetypeD')) myCmd = paste0(myCmd, ', direction = linetypeD')
myCmd = paste0(myCmd, '))')
eval(parse(text = myCmd))
}
if(exists('sizeV')){
p = p + aes_string(size = sizeV)
myCmd = 'p = p + guides(size = guide_legend(sizeT'
if(exists('sizeTP')) myCmd = paste0(myCmd, ', title.position = sizeTP')
if(exists('sizeLP')) myCmd = paste0(myCmd, ', label.position = sizeLP')
if(exists('sizeD')) myCmd = paste0(myCmd, ', direction = sizeD')
myCmd = paste0(myCmd, '))')
eval(parse(text = myCmd))
}
if(exists('weightV')){
p = p + aes_string(weight = weightV)
myCmd = 'p = p + guides(weight = guide_legend(weightT'
if(exists('weightTP')) myCmd = paste0(myCmd, ', title.position = weightTP')
if(exists('weightLP')) myCmd = paste0(myCmd, ', label.position = weightLP')
if(exists('weightD')) myCmd = paste0(myCmd, ', direction = weightD')
myCmd = paste0(myCmd, '))')
eval(parse(text = myCmd))
}
myCmd = paste0('p = p + geom_bar(show.legend = showGuide, stat = stat')
if(exists('binWidth')) myCmd = paste0(myCmd, ', binwidth = binWidth')
if(exists('myAlpha')) myCmd = paste0(myCmd, ', alpha = myAlpha')
if(exists('color')) myCmd = paste0(myCmd, ', color = color')
if(exists('fill')) myCmd = paste0(myCmd, ', fill = fill')
if(exists('size')) myCmd = paste0(myCmd, ', size = size')
if(exists('barWidth')) myCmd = paste0(myCmd, ', width = barWidth')
if(exists('position')) myCmd = paste0(myCmd, ', position = position')
myCmd = paste0(myCmd, ')')
if(exists('myFacet')){
myCmd = paste0(myCmd, ' + ', myFacet, '(', facetM)
if(exists('facetScl')) myCmd = paste0(myCmd, ', scale = facetScl')
if(exists('facetCol')) myCmd = paste0(myCmd, ', ncol = facetCol')
if(exists('facetRow')) myCmd = paste0(myCmd, ', nrow = facetRow')
myCmd = paste0(myCmd, ')')
p = p + theme(strip.text = element_text(size = 18))
}
eval(parse(text = myCmd))
if(exists('horizontal')) p = p + geom_hline(yintercept = horizontal, linetype = "longdash", size = 0.3)
if(exists('flip')) p = p + coord_flip()
if(exists('lgPos')) p = p + theme(legend.position = lgPos)
if(exists('lgPosX') && exists('lgPosY')) p = p + theme(legend.position = c(lgPosX, lgPosY))
p = p + theme(legend.title = element_text(size = lgTtlS), legend.text = element_text(size = lgTxtS))
if(exists('lgBox')) p = p + theme(legend.box = lgBox)
library(scales)
if(exists('xPer')) p = p + scale_x_continuous(labels = percent)
if(exists('yPer')) p = p + scale_y_continuous(labels = percent)
if(exists('xComma')) p = p + scale_x_continuous(labels = comma)
if(exists('yComma')) p = p + scale_y_continuous(labels = comma)
if(exists('axisRatio')) p = p + coord_fixed(ratio = axisRatio)
if(exists('annoTxt')) p = p + annotate('text', x = as.numeric(strsplit(annoTxtX, ',', fixed = T)),
y = as.numeric(strsplit(annoTxtY, ',', fixed = T)),
label = strsplit(annoTxt, ',', fixed = T))
if(exists('x1') && exists('x2')) p = p + coord_cartesian(xlim = c(x1, x2))
if(exists('y1') && exists('y2')) p = p + coord_cartesian(ylim = c(y1, y2))
if(exists('x1') && exists('x2') && exists('y1') && exists('y2')) p = p + coord_cartesian(xlim = c(x1, x2), ylim = c(y1, y2))
if(exists('xLog') || exists('yLog')){
library(scales)
if(exists('xLog')) p = p + scale_x_continuous(trans = log_trans(xLog)) + annotation_logticks(sides = 'b')
if(exists('yLog')) p = p + scale_y_continuous(trans = log_trans(yLog)) + annotation_logticks(sides = 'l')
p = p + theme(panel.grid.minor = element_blank())
}
if(exists('main')) p = p + ggtitle(main)
p = p + theme(plot.title = element_text(size = mainS, hjust = 0.5))
if(exists('xLab')) p = p + xlab(xLab)
p = p + theme(axis.title.x = element_text(size = xLblS),
axis.text.x = element_text(size = xTxtS, angle = xAngle, vjust = vJust))
if(exists('yLab')) p = p + ylab(yLab)
p = p + theme(axis.title.y = element_text(size = yLblS), axis.text.y = element_text(size = yTxtS))
if(exists('anno')){
if(exists('yPer')){
labels = paste0(data[[2]] * 100, '%')
}else{
labels = data[[2]]
}
p = p + annotate('text', x = 1:nrow(data), y = data[[2]]+annoTxtS*max(data[[2]])/250, label = labels, size = annoTxtS)
}
if(exists('errBarMinV') && exists('errBarMaxV')) p = p + geom_errorbar(aes_string(ymin = errBarMinV, ymax = errBarMaxV), width = errBarWidth)
p
}