13
13
# ' @param guide.line Nucleotide frequency guide line. Default: NULL (0.5).
14
14
# ' @param guide.line.color The color of guide line. Default: "red".
15
15
# ' @param guide.line.type The line type of guide line. Default: "dashed".
16
- # ' @param mark.type The mark type to highlight SNV position, choose from twill and star. Default: twill.
16
+ # ' @param mark.type The mark type to highlight SNV position, choose from twill (add twill to position with SNV),
17
+ # ' star (add star mark to position with SNV), and highlight (position without SNV is grey). Default: twill.
17
18
# ' @param star.size The size of star when \code{mark.type} is star. Default: 1.
18
19
# ' @param show.aa Logical value, whether to show amino acid. Default: TRUE.
19
20
# ' @param sens Sense to translate: F for forward sense and R for reverse sense.
@@ -186,6 +187,12 @@ ggplot_add.base <- function(object, plot, object_name) {
186
187
dplyr :: pull(Pos ) %> %
187
188
unique()
188
189
alt.pos.nuc.freq.long <- pos.nuc.freq.long %> % dplyr :: filter(Pos %in% c(alt.pos ))
190
+ # get position without alt
191
+ ref.pos <- pos.nuc.freq.long %> %
192
+ dplyr :: filter(Ref == Base & Total == Freq ) %> %
193
+ dplyr :: pull(Pos ) %> %
194
+ unique()
195
+ ref.pos.nuc.freq.long <- pos.nuc.freq.long %> % dplyr :: filter(Pos %in% c(ref.pos ))
189
196
# create label offset
190
197
pos.nuc.freq $ Offset <- nuc.offset
191
198
# add guide line
@@ -194,36 +201,55 @@ ggplot_add.base <- function(object, plot, object_name) {
194
201
guide.line <- 0.5
195
202
}
196
203
197
- # create plot
198
- base.plot <- ggplot() +
199
- geom_bar(
200
- data = pos.nuc.freq.long , aes_string(x = " Pos" , y = " Freq" , fill = " Base" ),
201
- position = " fill" , stat = " identity" , color = " white"
202
- )
203
-
204
204
# add mark
205
205
if (length(alt.pos ) > = 1 ) {
206
- if (mark.type == " twill" ) {
207
- base.plot <- base.plot +
208
- ggpattern :: geom_col_pattern(
209
- data = alt.pos.nuc.freq.long ,
210
- aes_string(
211
- x = " Pos" , y = " Freq" , pattern = " Base" , fill = " Base" ,
212
- pattern_fill = " Base" , pattern_angle = " Base"
213
- ),
214
- position = " fill" , colour = " black" ,
215
- pattern_density = 0.35 , pattern_key_scale_factor = 1.3
206
+ if (mark.type %in% c(" twill" , " star" )) {
207
+ # create plot
208
+ base.plot <- ggplot() +
209
+ geom_bar(
210
+ data = pos.nuc.freq.long , aes_string(x = " Pos" , y = " Freq" , fill = " Base" ),
211
+ position = " fill" , stat = " identity" , color = " white"
212
+ )
213
+ if (mark.type == " twill" ) {
214
+ base.plot <- base.plot +
215
+ ggpattern :: geom_col_pattern(
216
+ data = alt.pos.nuc.freq.long ,
217
+ aes_string(
218
+ x = " Pos" , y = " Freq" , pattern = " Base" , fill = " Base" ,
219
+ pattern_fill = " Base" , pattern_angle = " Base"
220
+ ),
221
+ position = " fill" , colour = " black" ,
222
+ pattern_density = 0.35 , pattern_key_scale_factor = 1.3
223
+ ) +
224
+ ggpattern :: scale_pattern_fill_manual(values = c(nuc.color , " white" ))
225
+ } else if (mark.type == " star" ) {
226
+ base.plot <- base.plot +
227
+ geom_point(
228
+ data = alt.pos.nuc.freq.long , aes_string(x = " Pos" , y = " 1.01" ),
229
+ shape = 8 , show.legend = FALSE , size = star.size
230
+ )
231
+ }
232
+ } else if (mark.type == " highlight" ) {
233
+ base.plot <- ggplot() +
234
+ geom_bar(
235
+ data = ref.pos.nuc.freq.long , aes_string(x = " Pos" , y = " Freq" ),
236
+ position = " fill" , stat = " identity" , color = " white" , fill = " grey"
216
237
) +
217
- ggpattern :: scale_pattern_fill_manual(values = c(nuc.color , " white" ))
218
- } else if (mark.type == " star" ) {
219
- base.plot <- base.plot +
220
- geom_point(
221
- data = alt.pos.nuc.freq.long , aes_string(x = " Pos" , y = " 1.01" ),
222
- shape = 8 , show.legend = FALSE , size = star.size
238
+ geom_bar(
239
+ data = alt.pos.nuc.freq.long , aes_string(x = " Pos" , y = " Freq" , fill = " Base" ),
240
+ position = " fill" , stat = " identity" , color = " white"
223
241
)
242
+ } else {
243
+ stop(" The mark.type you provided is not valid, please choose from twill, star, highlight." )
224
244
}
225
245
} else {
226
246
message(" No SNV detected, do not add mark!" )
247
+ # create plot
248
+ base.plot <- ggplot() +
249
+ geom_bar(
250
+ data = pos.nuc.freq.long , aes_string(x = " Pos" , y = " Freq" , fill = " Base" ),
251
+ position = " fill" , stat = " identity" , color = " white"
252
+ )
227
253
}
228
254
229
255
if (show.aa ) {
0 commit comments