Skip to content

Commit

Permalink
Change line width based on number of samples
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjcroucher committed May 29, 2024
1 parent 29d1792 commit cf77eaa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions R/scripts/plot_gubbins.R
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ plot_gubbins_recombination <- function(gubbins_rec,gubbins_tree, start_pos = NA,
tidyr::unnest_longer(gene,
values_to = "Taxa") %>%
dplyr::mutate(Taxa = factor(Taxa,
levels = rev(get_taxa_name(gubbins_tree)))) %>%
levels = rev(ggtree::get_taxa_name(gubbins_tree)))) %>%
dplyr::mutate(length = end - start + 1) %>%
dplyr::arrange(rev(length)) %>%
dplyr::select(-length)
Expand All @@ -543,6 +543,16 @@ plot_gubbins_recombination <- function(gubbins_rec,gubbins_tree, start_pos = NA,
trim_start(start_pos) %>%
trim_end(end_pos)

# Get the number of taxa for selecting the line width
n_taxa <- length(ggtree::get_taxa_name(gubbins_tree))
rec_linewidth <-
dplyr::case_when(
n_taxa < 10 ~ 5,
n_taxa < 50 ~ 2,
n_taxa < 100 ~ 1.5,
TRUE ~ 1
)

# Plot recombination
rec_plot <-
ggplot(gubbins_rec,
Expand All @@ -551,7 +561,8 @@ plot_gubbins_recombination <- function(gubbins_rec,gubbins_tree, start_pos = NA,
y = Taxa,
yend = Taxa,
colour = Colour)) +
geom_segment(alpha = 0.25) +
geom_segment(alpha = 0.5,
linewidth = rec_linewidth) +
scale_colour_manual(values = c("red" = "red",
"blue" = "blue")) +
scale_y_discrete(drop = FALSE) +
Expand Down

0 comments on commit cf77eaa

Please sign in to comment.