-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteCmd-2_function.R
465 lines (419 loc) · 22 KB
/
writeCmd-2_function.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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
dat_chr_cum <- function(dat, chr.cum.len) {
dat$start <- 0
dat$pos <- (dat$start + dat$size) / 2
dat$chr <- factor(dat$chr, levels = names(chr.cum.len), ordered = T)
dat$pos <- dat$pos + chr.cum.len[dat$chr]
dat$chr <- as.character(dat$chr)
return(dat)
}
areColors <- function(x) {
sapply(x, function(y) {
tryCatch(is.matrix(col2rgb(y)), error = function(e) FALSE)
})
}
dat_dis_col <- function(i, dis_cols, dat) {
dis_col <- dis_cols[i]
dis_col <- gsub("\\s", "", strsplit(dis_col, ",")[[1]])
dis_col <- gsub('\\"', "", dis_col)
dis_col <- gsub("0x", "#", dis_col)
if (length(dis_col) == 0) {
dis_col <- NA
}
dat$color <- dis_col
return(dat)
}
dat_cus_cols <- function(i, cus_cols, dat) {
laycolor <- cus_cols[i]
laycolor <- unlist(strsplit(laycolor, ";"))
laycolor <- data.frame(id = laycolor, stringsAsFactors = F)
laycolor$group <- gsub("\\:.*", "", laycolor$id)
laycolor$cols <- gsub(".*\\:", "", laycolor$id)
laycolor$group <- gsub(" ", "", laycolor$group)
laycolor$cols <- gsub(" ", "", laycolor$cols)
colname <- colnames(dat)
dat <- merge(dat, laycolor, by.x = "color", by.y = "group", all.x = T)
dat <- dat[c(colname, "cols")]
return(dat)
}
lgd_mdy_label <- function(i, lgd_labels) {
lgd_label <- gsub("\\s", "", strsplit(lgd_labels[i], ",")[[1]])
lgd_label <- gsub('\\"', "", lgd_label)
if (length(lgd_label) == 0) {
lgd_label <- "NA"
}
return(lgd_label)
}
chr_cumsum <- function(dat, i) {
chr.len <- dat$size
names(chr.len) <- dat$chr
if (i == 2) {
chr.cum.len.tmp <<- c(0, cumsum(chr.len))
}
chr.cum.len <- c(0, cumsum(chr.len)[-length(chr.len)])
names(chr.cum.len) <- names(chr.len)
return(chr.cum.len)
}
cols_adjust <- function(i, dat, col_transpt, plot_type, type) {
if ((type == 1 && (plot_type[i] %in% c("rect_discrete", "heatmap_discrete"))) |
(type == 2 && (!plot_type[i] %in% c("point_gradual", "rect_gradual")))) {
dat$color[!areColors(dat$color)] <- NA
dat$color <- adjustcolor(dat$color, alpha.f = col_transpt[i])
if (!all(is.na(dat$color))) {
dat_val <- unique(dat$raw_color[!is.na(dat$raw_color)])
dat_col <- dat$color[match(dat_val, dat$raw_color)]
} else{
dat_val <- unique(dat$raw_color[!is.na(dat$raw_color)])[1]
dat_col <- "#FFFFFF00"
}
} else if (!plot_type[i] %in% c("heatmap_gradual", "heatmap_discrete", "text",
"rect_gradual", "rect_discrete", "ideogram")){
if (!"raw_color" %in% names(dat)) {
dat$raw_color <- dat$color
}
if (!plot_type[i] %in% "segment") {
dat_val <- unique(dat$raw_color[!is.na(dat$value)])
} else{
dat_val <- unique(dat$raw_color)
}
if (plot_type[i] %in% "vertical_line") {
dat_val <- unique(dat$raw_color)
}
dat$color[!areColors(dat$color)] <- NA
dat$color <- adjustcolor(dat$color, alpha.f = col_transpt[i])
dat_col <- dat$color[match(dat_val, dat$raw_color)]
}
dat_val <- dat_val[!duplicated(dat_col)]
dat_col <- dat_col[!duplicated(dat_col)]
dat$raw_color <- factor(dat$raw_color, levels = dat_val, ordered = T)
dat$color <- factor(dat$color, levels = dat_col, ordered = T)
dat_val <<- dat_val[which(!dat_col %in% "#FFFFFF00")]
dat_col <<- dat_col[!dat_col %in% "#FFFFFF00"]
return(dat)
}
# the main function to make two genomes plot
two_genomes_plot <- function(data.chr1, data.chr2, data.2geno.plot, Height, Width, theme_sty, font_size, xtitle, ytitle, title_font_face, xlabel,
ylabel, lgd_pos, lgd_title_size, lgd_title_font_face, lgd_text_size, lgd_text_font_face, tc_chr_data1, tc_chr_data2,
trackfil, plot_type, sel_gral_col, gral_col_tp, gral_2cols_ct, gral_3cols_ct, col_type, color_cus, color_mulgp,
col_transpt, symbol_point, symbol_point_type, point_size, point_size_type, line_size, vertical, vertical_col,
vertical_size, vertical_type, horizontal, horizontal_col, horizontal_size, horizontal_type, add_border, border_col,
linetype, col_lgd, col_lgd_name, size_lgd, size_lgd_name, shape_lgd, shape_lgd_name, col_lgd_mdy_label, col_lgd_label,
size_lgd_mdy_label, size_lgd_label, shape_lgd_mdy_label, shape_lgd_label, laycolor.export) {
## *** Modify two genomes data ***
names(data.chr1) <- c("chr", "size")
data.chr1$size <- as.numeric(data.chr1$size)
names(data.chr2) <- c("chr", "size")
data.chr2$size <- as.numeric(data.chr2$size)
tc_p1 <- ggplot()
## *** Plot theme ***
tc_alltheme_sty <-
list(
theme_bw(), theme_classic(), theme_minimal(), theme_few(), theme_grey(), theme_tufte(),
theme_calc(), theme_void(), theme_base(), theme_linedraw(), theme_economist(), theme_excel(),
theme_fivethirtyeight(), theme_gdocs(), theme_hc(), theme_pander(), theme_solarized(), theme_wsj()
)
tc_p1 <- tc_p1 + tc_alltheme_sty[[as.numeric(gsub("theme", "", theme_sty))]]
## *** Modify main plot data ***
if (plot_type %in% c("point_gradual", "point_discrete")) {
names(data.2geno.plot)[1:4] <- c("chr1", "pos1", "chr2", "pos2")
data.2geno.plot[c("pos1", "pos2")] <- sapply(data.2geno.plot[c("pos1", "pos2")], as.numeric)
if(plot_type %in% "point_gradual"){
data.2geno.plot[,5] <- as.numeric(data.2geno.plot[,5])
}
}
if (plot_type %in% c("segment", "rect_gradual", "rect_discrete")) {
names(data.2geno.plot)[1:6] <- c("chr1", "xpos1", "xpos2", "chr2", "ypos1", "ypos2")
data.2geno.plot[c("xpos1", "xpos2", "ypos1", "ypos2")] <- sapply(data.2geno.plot[c("xpos1", "xpos2", "ypos1", "ypos2")], as.numeric)
if(plot_type %in% "rect_gradual"){
data.2geno.plot[,7] <- as.numeric(data.2geno.plot[,7])
}
}
## *** Color ***
if (plot_type %in% c("point_gradual", "rect_gradual")) {
if (sel_gral_col == 1) {
gralcols <- gsub('\\"', "", gral_col_tp)
}else if(sel_gral_col == 2){
gralcols <- gral_2cols_ct
}else if (sel_gral_col == 3){
gralcols <- gral_3cols_ct
}
gralcols <- unlist(strsplit(gralcols, "\\."))
}
if (plot_type %in% c("point_discrete", "segment", "rect_discrete")) {
if (col_type == 2) {
data.2geno.plot <- dat_dis_col(1, color_cus, data.2geno.plot)
} else if (col_type == 3 & ("color" %in% colnames(data.2geno.plot))) {
data.2geno.plot <- dat_cus_cols(1, color_mulgp, data.2geno.plot)
laycolor <- unique(data.2geno.plot$cols)
data.2geno.plot$raw_color <- data.2geno.plot$color
data.2geno.plot$color <- data.2geno.plot$cols
data.2geno.plot$cols <- NULL
} else if (col_type == 1 & ("color" %in% colnames(data.2geno.plot))) {
laycolor <- unlist(strsplit(laycolor.export, "\\."))
laycolor <- data.frame(group = unique(data.2geno.plot$color), cols = laycolor, stringsAsFactors = F)
colname <- colnames(data.2geno.plot)
data.2geno.plot <- merge(data.2geno.plot, laycolor, by.x = "color", by.y = "group", all.x = T)
data.2geno.plot <- data.2geno.plot[c(colname, "cols")]
laycolor <- unique(data.2geno.plot$cols)
data.2geno.plot$raw_color <- data.2geno.plot$color
data.2geno.plot$color <- data.2geno.plot$cols
data.2geno.plot$cols <- NULL
} else{
laycolor <- unlist(strsplit(laycolor.export, "\\."))
data.2geno.plot$color <- laycolor
}
}
## *** The color labels ***
if (!plot_type %in% c("point_gradual", "rect_gradual")) {
if (!"raw_color" %in% names(data.2geno.plot)) {
data.2geno.plot$raw_color <- data.2geno.plot$color
}
dat_val <<- NULL
dat_col <<- NULL
data.2geno.plot <- cols_adjust(1, data.2geno.plot, col_transpt, plot_type, 2)
labelscol <- dat_val
breakscol <- dat_col
}
## *** Point type and size ***
if (plot_type %in% c("point_gradual", "point_discrete")) {
if (symbol_point_type == 1) {
data.2geno.plot$shape <- as.numeric(symbol_point)
} else if (symbol_point_type == 2 & (!"shape" %in% names(data.2geno.plot))) {
data.2geno.plot$shape <- 16
}
if (point_size_type == 1) {
data.2geno.plot$size <- as.numeric(point_size)
} else if (point_size_type == 2 & (!"size" %in% names(data.2geno.plot))) {
data.2geno.plot$size <- 0.8
}
breakspch <- unique(data.2geno.plot$shape)
labelspch <- breakspch
breakscex <- unique(data.2geno.plot$size)
labelscex <- breakscex
}
## *** Borders ***
if (add_border == 2) {
border_col <- NA
}
## *** Legends ***
add_col_lgd <- "none"; add_size_lgd <- "none"; add_shape_lgd <- "none"
if (col_lgd == 1) {
if (plot_type %in% c("point_gradual", "rect_gradual")) {
add_col_lgd <- "colourbar"
} else{
add_col_lgd <- "legend"
}
if (plot_type %in% c("point_discrete", "segment", "rect_discrete")) {
if (col_lgd_mdy_label == 1) {
col_lgd_labelp <- lgd_mdy_label(1, col_lgd_label)
col_lgd_labelp <- rep(col_lgd_labelp, length(breakscol))[1:length(breakscol)]
names(col_lgd_labelp) <- labelscol
data.2geno.plot$raw_color <- as.character(data.2geno.plot$raw_color)
data.2geno.plot$raw_color <- col_lgd_labelp[data.2geno.plot$raw_color]
labelscol <- unname(col_lgd_labelp)
data.2geno.plot$raw_color <- factor(data.2geno.plot$raw_color, levels = unique(labelscol), ordered = T)
}
}
}
if (plot_type %in% c("point_gradual", "point_discrete")) {
if (size_lgd == 1) {
add_size_lgd <- "legend"
if (size_lgd_mdy_label == 1) {
size_lgd_labelp <- lgd_mdy_label(1, size_lgd_label)
labelscex <- rep(size_lgd_labelp, length(breakscex))[1:length(breakscex)]
}
}
if (shape_lgd == 1) {
add_shape_lgd <- "legend"
if (shape_lgd_mdy_label == 1) {
shape_lgd_labelp <- lgd_mdy_label(1, shape_lgd_label)
labelspch <- rep(shape_lgd_labelp, length(breakspch))[1:length(breakspch)]
}
}
}
## *** The position of concatenated genome1 ***
chr.cum.len <- chr_cumsum(data.chr1, 2)
chr.cum.len_1 <- chr.cum.len.tmp
data.chr1 <- dat_chr_cum(data.chr1, chr.cum.len)
data.2geno.plot$chr1 <- factor(data.2geno.plot$chr1, levels = names(chr.cum.len), ordered = T)
if (plot_type %in% c("segment", "rect_gradual", "rect_discrete")) {
data.2geno.plot$xpos1 <- data.2geno.plot$xpos1 + chr.cum.len[data.2geno.plot$chr1]
data.2geno.plot$xpos2 <- data.2geno.plot$xpos2 + chr.cum.len[data.2geno.plot$chr1]
} else{
data.2geno.plot$pos1 <- data.2geno.plot$pos1 + chr.cum.len[data.2geno.plot$chr1]
}
data.2geno.plot$chr1 <- as.character(data.2geno.plot$chr1)
## *** The position of concatenated genome2 ***
chr.cum.len <- chr_cumsum(data.chr2, 2)
chr.cum.len_2 <- chr.cum.len.tmp
data.chr2 <- dat_chr_cum(data.chr2, chr.cum.len)
data.2geno.plot$chr2 <- factor(data.2geno.plot$chr2, levels = names(chr.cum.len), ordered = T)
if (plot_type %in% c("segment", "rect_gradual", "rect_discrete")) {
data.2geno.plot$ypos1 <- data.2geno.plot$ypos1 + chr.cum.len[data.2geno.plot$chr2]
data.2geno.plot$ypos2 <- data.2geno.plot$ypos2 + chr.cum.len[data.2geno.plot$chr2]
} else{
data.2geno.plot$pos2 <- data.2geno.plot$pos2 + chr.cum.len[data.2geno.plot$chr2]
}
data.2geno.plot$chr2 <- as.character(data.2geno.plot$chr2)
## *** Point_gradual ***
if (plot_type == "point_gradual") {
midpoint <- mean(data.2geno.plot$color, na.rm = T)
if (is.numeric(labelscex)) {
labelscex <- sprintf("%.1f", sort(labelscex))
}
if (is.numeric(labelspch)) {
labelspch <- sort(labelspch)
}
if (lgd_pos == 1) {
tc_p1 <- tc_p1 + geom_point(data = data.2geno.plot, aes(x = pos1, y = pos2, color = color, shape = as.character(shape), size = size))
if(sel_gral_col == 2){
tc_p1 <- tc_p1 + scale_color_gradient(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], high = gralcols[2], na.value = "#FFFFFF00")
}else{
tc_p1 <- tc_p1 + scale_color_gradient2(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], midpoint = midpoint,
mid = gralcols[2], high = gralcols[3], na.value = "#FFFFFF00")
}
tc_p1 <- tc_p1 + scale_size_identity(name = size_lgd_name, guide = add_size_lgd, breaks = sort(breakscex), labels = labelscex)
tc_p1 <- tc_p1 + scale_shape_manual(name = shape_lgd_name, guide = add_shape_lgd, values = sort(breakspch), labels = labelspch)
tc_p1 <- tc_p1 + theme(legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
} else{
tc_p1 <- tc_p1 + geom_point(data = data.2geno.plot, aes(x = pos1, y = pos2, color = color, shape = as.character(shape), size = size))
if(sel_gral_col == 2){
tc_p1 <- tc_p1 + scale_color_gradient(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], high = gralcols[2], na.value = "#FFFFFF00")
}else{
tc_p1 <- tc_p1 + scale_color_gradient2(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], midpoint = midpoint,
mid = gralcols[2], high = gralcols[3], na.value = "#FFFFFF00")
}
tc_p1 <- tc_p1 + scale_size_identity(name = size_lgd_name, guide = add_size_lgd, breaks = sort(breakscex), labels = labelscex)
tc_p1 <- tc_p1 + scale_shape_manual(name = shape_lgd_name, guide = add_shape_lgd, values = sort(breakspch), labels = labelspch)
tc_p1 <- tc_p1 + theme(legend.position = "bottom", legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
}
if (add_col_lgd == "colourbar") {
tc_p1 <- tc_p1 + guides(color = guide_colorbar(order = 1, title.vjust = 0.8, title.hjust = 0.4), size = guide_legend(order = 2))
} else{
tc_p1 <- tc_p1 + guides(size = guide_legend(order = 1))
}
}
## *** Point_discrete ***
if (plot_type == "point_discrete") {
if (is.numeric(labelscex)) {
labelscex <- sprintf("%.1f", sort(labelscex))
}
if (is.numeric(labelspch)) {
labelspch <- sort(labelspch)
}
if (lgd_pos == 1) {
tc_p1 <- tc_p1 + geom_point(data = data.2geno.plot, aes(pos1, pos2, color = color, shape = as.character(shape), size = size))
tc_p1 <- tc_p1 + scale_color_identity(name = col_lgd_name, guide = add_col_lgd, breaks = breakscol, labels = labelscol)
tc_p1 <- tc_p1 + scale_size_identity(name = size_lgd_name, guide = add_size_lgd, breaks = sort(breakscex), labels = labelscex)
tc_p1 <- tc_p1 + scale_shape_manual(name = shape_lgd_name, guide = add_shape_lgd, values = sort(breakspch), labels = labelspch)
tc_p1 <- tc_p1 + theme(legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
tc_p1 <- tc_p1 + guides(color = guide_legend(order = 1), size = guide_legend(order = 2))
} else{
tc_p1 <- tc_p1 + geom_point(data = data.2geno.plot, aes(pos1, pos2, color = color, shape = as.character(shape), size = size))
tc_p1 <- tc_p1 + scale_color_identity(name = col_lgd_name, guide = add_col_lgd, breaks = breakscol, labels = labelscol)
tc_p1 <- tc_p1 + scale_size_identity(name = size_lgd_name, guide = add_size_lgd, breaks = sort(breakscex), labels = labelscex)
tc_p1 <- tc_p1 + scale_shape_manual(name = shape_lgd_name, guide = add_shape_lgd, values = sort(breakspch), labels = labelspch)
tc_p1 <- tc_p1 + theme(legend.position = "bottom", legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
tc_p1 <- tc_p1 + guides(color = guide_legend(order = 1), size = guide_legend(order = 2))
}
}
## *** Segment ***
if (plot_type == "segment") {
if (length(unique(data.2geno.plot$color)) > 1) {
linetype <- "solid"
}
if (lgd_pos == 1) {
tc_p1 <- tc_p1 + geom_segment(data = data.2geno.plot, aes(x = xpos1, y = ypos1, xend = xpos2, yend = ypos2, color = color),
size = line_size, linetype = linetype)
tc_p1 <- tc_p1 + scale_color_identity(name = col_lgd_name, guide = add_col_lgd, breaks = breakscol, labels = labelscol)
tc_p1 <- tc_p1 + theme(legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
} else{
tc_p1 <- tc_p1 + geom_segment(data = data.2geno.plot, aes(x = xpos1, y = ypos1, xend = xpos2, yend = ypos2, color = color),
size = line_size, linetype = linetype)
tc_p1 <- tc_p1 + scale_color_identity(name = col_lgd_name, guide = add_col_lgd, breaks = breakscol, labels = labelscol)
tc_p1 <- tc_p1 + theme(legend.position = "bottom", legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
}
}
## *** Rect_gradual ***
if (plot_type == "rect_gradual") {
midpoint <- mean(data.2geno.plot$color, na.rm = T)
if (lgd_pos == 1) {
tc_p1 <- tc_p1 + geom_rect(data = data.2geno.plot, aes(xmin = xpos1, xmax = xpos2, ymin = ypos1, ymax = ypos2,
fill = color), color = border_col)
if(sel_gral_col == 2){
tc_p1 <- tc_p1 + scale_fill_gradient(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], high = gralcols[2], na.value = "#FFFFFF00")
}else{
tc_p1 <- tc_p1 + scale_fill_gradient2(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], midpoint = midpoint,
mid = gralcols[2], high = gralcols[3], na.value = "#FFFFFF00")
}
tc_p1 <- tc_p1 + theme(legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
} else{
tc_p1 <- tc_p1 + geom_rect(data = data.2geno.plot, aes(xmin = xpos1, xmax = xpos2, ymin = ypos1, ymax = ypos2, fill = color), color = border_col)
if(sel_gral_col == 2){
tc_p1 <- tc_p1 + scale_fill_gradient(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], high = gralcols[2], na.value = "#FFFFFF00")
}else{
tc_p1 <- tc_p1 + scale_fill_gradient2(name = col_lgd_name, guide = add_col_lgd, low = gralcols[1], midpoint = midpoint,
mid = gralcols[2], high = gralcols[3], na.value = "#FFFFFF00")
}
tc_p1 <- tc_p1 + theme(legend.position = "bottom", legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
if(add_col_lgd != "none"){
tc_p1 <- tc_p1 + guides(fill = guide_colourbar(title.vjust = 0.8, title.hjust = 0.4))
}
}
}
## *** Rect_discrete ***
if (plot_type == "rect_discrete") {
if (lgd_pos == 1) {
tc_p1 <- tc_p1 + geom_rect(data = data.2geno.plot, aes(xmin = xpos1, xmax = xpos2, ymin = ypos1, ymax = ypos2,
fill = color), color = border_col)
tc_p1 <- tc_p1 + scale_fill_identity(name = col_lgd_name, guide = add_col_lgd, breaks = breakscol, labels = labelscol)
tc_p1 <- tc_p1 + theme(legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
} else{
tc_p1 <- tc_p1 + geom_rect(data = data.2geno.plot, aes(xmin = xpos1, xmax = xpos2, ymin = ypos1, ymax = ypos2,
fill = color), color = border_col)
tc_p1 <- tc_p1 + scale_fill_identity(name = col_lgd_name, guide = add_col_lgd, breaks = breakscol, labels = labelscol)
tc_p1 <- tc_p1 + theme(legend.position = "bottom", legend.title = element_text(size = lgd_title_size, face = lgd_title_font_face),
legend.text = element_text(size = lgd_text_size, face = lgd_text_font_face), legend.key = element_rect(fill = NA))
}
}
## *** Vertical line ***
if (vertical == 1) {
tc_p1 <- tc_p1 + geom_vline(xintercept = chr.cum.len_1, linetype = vertical_type,
color = vertical_col, size = vertical_size)
}
## *** Horizontal line ***
if (horizontal == 1) {
tc_p1 <- tc_p1 + geom_hline(yintercept = chr.cum.len_2, linetype = horizontal_type,
color = horizontal_col, size = horizontal_size)
}
## *** The axis label ***
if (xlabel == 1) {
tc_p1 <- tc_p1 + scale_x_continuous(breaks = data.chr1$pos, labels = data.chr1$chr)
} else{
tc_p1 <- tc_p1 + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
}
if (ylabel == 1) {
tc_p1 <- tc_p1 + scale_y_continuous(breaks = data.chr2$pos, labels = data.chr2$chr)
} else{
tc_p1 <- tc_p1 + theme(axis.text.y = element_blank(), axis.ticks.y = element_blank())
}
## *** The x and y axis title ***
tc_p1 <- tc_p1 + xlab(xtitle) + ylab(ytitle)
## *** The font angle of axis title ***
if (any(theme_sty %in% c("theme8", "theme16"))) {
tc_p1 <- tc_p1 + theme(axis.title.x = element_text(hjust = 0.5, vjust = 1), axis.title.y = element_text(angle = 90, hjust = 0.5, vjust = 0.1))
}
## *** Font face ***
tc_p1 <- tc_p1 + theme(axis.title = element_text(face = title_font_face))
## *** Font size ***
tc_p1 <- tc_p1 + theme(text = element_text(size = font_size))
return(tc_p1)
}