-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColorKeyboard.R
More file actions
247 lines (220 loc) · 7.43 KB
/
ColorKeyboard.R
File metadata and controls
247 lines (220 loc) · 7.43 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
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
# Author: Benben Miao
# Email: benben.miao@outlook.com
# Rversion: 4.2.0
# Date: 2022-11-30
# -> 0. Install and Library
# install.packages(c("ggplot2", "ggsci"))
# devtools::install_github("sharlagelfand/ggkeyboard", ref = "main")
library(ggplot2)
library(ggsci)
library(ggkeyboard)
# <- 0. Install and Library
options (warn = -1)
# -> 1. File Read
# file_path = "data/HexbinHive/HexbinHive.txt"
# file_format = "txt"
# # "xlsx", "xls", "txt", "csv"
#
# if (file_format == "xlsx" | file_format == "xls") {
# data <- readxl::read_excel(path = file_path,
# sheet = NULL,
# col_names = TRUE,
# na = "",
# progress = readxl::readxl_progress()
# )
# } else if (file_format == "txt" | file_format == "csv") {
# data <- read.table(file = file_path,
# header = TRUE,
# sep = "\t",
# stringsAsFactors = F
# )
# } else if (file_format == "csv") {
# data <- read.table(file = file_path,
# header = TRUE,
# sep = ",",
# stringsAsFactors = F
# )
# }
# <- 1. File Read
# -> 2. Data Operation
# set.seed(123)
# df <- data.frame(x = rnorm(2000), y = rnorm(2000))
# write.table(df, "HexbinHive.txt", quote = F, sep = "\t", row.names = F)
# <- 2. Data Operation
# -> 3. Plot Parameters
fonts <- "Times"
# ChoiceBox: "Times", "Palatino", "Bookman", "Courier", "Helvetica", "URWGothic", "NimbusMon", "NimbusSan"
ggTheme <- "theme_light"
# ChoiceBox: "theme_default", "theme_bw", "theme_gray", "theme_light", "theme_linedraw", "theme_dark", "theme_minimal", "theme_classic", "theme_void"
if (ggTheme == "theme_default") {
gg_theme <- theme()
} else if (ggTheme == "theme_bw") {
gg_theme <- theme_bw()
} else if (ggTheme == "theme_gray") {
gg_theme <- theme_gray()
} else if (ggTheme == "theme_light") {
gg_theme <- theme_light()
} else if (ggTheme == "theme_linedraw") {
gg_theme <- theme_linedraw()
} else if (ggTheme == "theme_dark") {
gg_theme <- theme_dark()
} else if (ggTheme == "theme_minimal") {
gg_theme <- theme_minimal()
} else if (ggTheme == "theme_classic") {
gg_theme <- theme_classic()
} else if (ggTheme == "theme_void") {
gg_theme <- theme_void()
} else if (ggTheme == "theme_test") {
gg_theme <- theme_test()
}
sciFillAlpha <- 0.80
sciColorAlpha <- 0.80
sciFillColor <- "Sci_NPG"
# ChoiceBox: "Sci_AAAS", "Sci_NPG", "Sci_Simpsons", "Sci_JAMA", "Sci_GSEA", "Sci_Lancet", "Sci_Futurama", "Sci_JCO", "Sci_NEJM", "Sci_IGV", "Sci_UCSC", "Sci_D3", "Sci_Material"
if (sciFillColor == "Default"){
sci_fill <- NULL
sci_color <- NULL
} else if (sciFillColor == "Sci_AAAS") {
sci_fill <- scale_fill_aaas(alpha = sciFillAlpha)
sci_color <- scale_color_aaas(alpha = sciColorAlpha)
# Science and Science Translational Medicine:
} else if (sciFillColor == "Sci_NPG") {
sci_fill <- scale_fill_npg(alpha = sciFillAlpha)
sci_color <- scale_color_npg(alpha = sciColorAlpha)
} else if (sciFillColor == "Sci_Simpsons") {
sci_fill <- scale_fill_simpsons(alpha = sciFillAlpha)
sci_color <- scale_color_simpsons(alpha = sciColorAlpha)
# The Simpsons
} else if (sciFillColor == "Sci_JAMA") {
sci_fill <- scale_fill_jama(alpha = sciFillAlpha)
sci_color <- scale_color_jama(alpha = sciColorAlpha)
# The Journal of the American Medical Association
} else if (sciFillColor == "Sci_Lancet") {
sci_fill <- scale_fill_lancet(alpha = sciFillAlpha)
sci_color <- scale_color_lancet(alpha = sciColorAlpha)
# Lancet Oncology
} else if (sciFillColor == "Sci_Futurama") {
sci_fill <- scale_fill_futurama(alpha = sciFillAlpha)
sci_color <- scale_color_futurama(alpha = sciColorAlpha)
# Futurama
} else if (sciFillColor == "Sci_JCO") {
sci_fill <- scale_fill_jco(alpha = sciFillAlpha)
sci_color <- scale_color_jco(alpha = sciColorAlpha)
# Journal of Clinical Oncology:
} else if (sciFillColor == "Sci_NEJM") {
sci_fill <- scale_fill_nejm(alpha = sciFillAlpha)
sci_color <- scale_color_nejm(alpha = sciColorAlpha)
# The New England Journal of Medicine
} else if (sciFillColor == "Sci_IGV") {
sci_fill <- scale_fill_igv(alpha = sciFillAlpha)
sci_color <- scale_color_igv(alpha = sciColorAlpha)
# Integrative Genomics Viewer (IGV)
} else if (sciFillColor == "Sci_UCSC") {
sci_fill <- scale_fill_ucscgb(alpha = sciFillAlpha)
sci_color <- scale_color_ucscgb(alpha = sciColorAlpha)
# UCSC Genome Browser chromosome sci_fill
} else if (sciFillColor == "Sci_D3") {
sci_fill <- scale_fill_d3(alpha = sciFillAlpha)
sci_color <- scale_color_d3(alpha = sciColorAlpha)
# D3.JS
} else if (sciFillColor == "Sci_Material") {
sci_fill <- scale_fill_material(alpha = sciFillAlpha)
sci_color <- scale_color_material(alpha = sciColorAlpha)
# The Material Design color palettes
}
title <- "Hexbin Hive"
# TextField
xlab <- colnames(data)[1]
ylab <- colnames(data)[2]
keyboardType <- "Tenkeyless"
# ChoiceBox: "Tenkeyless", "Mac", "Full", "SixtyPercent"
if (keyboardType == "Tenkeyless") {
keyboard <- tkl
} else if (keyboardType == "Full") {
keyboard <- full
} else if (keyboardType == "SixtyPercent") {
keyboard <- sixty_percent
} else if (keyboardType == "Mac") {
keyboard <- mac
}
keyboardPalette <- "pastel"
# ChoiceBox: "pastel", "serika", "wahtsy", "cyberpunk", "magic", "varmilo", "t0mb3ry"
layout <- "ansi"
# "ansi", "iso"
keyTextSize <- 3
# Slider: 3, 0, 10, 1
plotTitleFace <- "bold"
# ChoiceBox: "plain", "italic", "bold", "bold.italic"
plotTitleSize <- 18
# Slider: 18, 0, 50, 1
plotTitleHjust <- 0.5
# Slider: 0.5, 0.0, 1.0, 0.1
axisTitleFace <- "bold"
# ChoiceBox: "plain", "italic", "bold", "bold.italic"
axisTitleSize <- 14
# Slider: 16, 0, 50, 1
axisTextSize <- 10
# Slider: 10, 0, 50, 1
legendTitleSize <- 12
# Slider: 12, 0, 50, 1
legendPosition <- "right"
# ChoiceBox: "none", "left", "right", "bottom", "top"
legendDirection <- "vertical"
# ChoiceBox: "horizontal", "vertical"
# <- 3. Plot Parameters
# # -> 4. Plot
p <- ggkeyboard(keyboard = keyboard,
# tkl, full, sixty_percent, mac
palette = keyboard_palette(keyboardPalette),
# c("pastel", "serika", "wahtsy", "cyberpunk", "magic", "varmilo", "t0mb3ry")
layout = layout,
# "ansi", "iso"
font_family = fonts,
font_size = keyTextSize,
adjust_text_colour = TRUE,
measurements = keyboard_measurements("default")
)
# %>%
# highlight_keys(c("A", "W", "S", "D"),
# colour = "#ff000088",
# fill = "#ff000055"
# )
# # <- 4. Plot
# -> 5. Save parameters
pdf_name = "results.pdf"
jpeg_name = "results.jpeg"
device_pdf = "pdf"
device_jpeg = "jpeg"
# "pdf", "jpeg", "tiff", "png", "bmp", "svg"
width = 10.0
height = 6.18
units = "in"
# "in", "cm", "mm", "px"
dpi <- 300
# <- 5. Save parameters
# -> 6. Save Image
ggsave(
filename = pdf_name,
plot = p,
device = device_pdf,
path = NULL,
scale = 1,
width = width,
height = height,
units = units,
dpi = 300,
limitsize = TRUE
)
ggsave(
filename = jpeg_name,
plot = p,
device = device_jpeg,
path = NULL,
scale = 1,
width = width,
height = height,
units = units,
dpi = 300,
limitsize = TRUE
)
# <- 6. Save Image