Skip to content

Commit

Permalink
Fix appearance bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jpquast committed Mar 17, 2024
1 parent dfcabc1 commit 0272a72
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 44 deletions.
31 changes: 22 additions & 9 deletions R/qc_charge_states.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ qc_charge_states <-
))
}

label_positions <- result %>%
dplyr::group_by({{ sample }}) %>%
dplyr::arrange(desc({{ charge_states }})) %>%
dplyr::mutate(label_y = cumsum(.data$charge_per)) %>%
dplyr::filter(.data$charge_per > 5)

if (plot == FALSE) {
return(result)
} else {
Expand All @@ -123,9 +129,10 @@ qc_charge_states <-
{
if (interactive == FALSE) {
geom_text(
data = result %>% dplyr::filter(.data$charge_per > 5),
aes(label = round(.data$charge_per, digits = 1)),
position = position_stack(vjust = 0.9)
data = label_positions,
aes(y = label_y,
label = round(.data$charge_per, digits = 1)),
vjust = 1.5
)
}
} +
Expand All @@ -139,7 +146,7 @@ qc_charge_states <-
theme_bw() +
theme(
plot.title = ggplot2::element_text(size = 20),
axis.title.x = ggplot2::element_text(size = 15),
axis.title.x = ggplot2::element_blank(),
axis.text.y = ggplot2::element_text(size = 15),
axis.text.x = ggplot2::element_text(size = 12, angle = 75, hjust = 1),
axis.title.y = ggplot2::element_text(size = 15),
Expand Down Expand Up @@ -169,6 +176,12 @@ qc_charge_states <-
))
}

label_positions <- result %>%
dplyr::group_by({{ sample }}) %>%
dplyr::arrange(desc({{ charge_states }})) %>%
dplyr::mutate(label_y = cumsum(.data$charge_per)) %>%
dplyr::filter(.data$charge_per > 5)

if (plot == FALSE) {
return(result)
} else {
Expand All @@ -178,23 +191,23 @@ qc_charge_states <-
{
if (interactive == FALSE) {
geom_text(
data = result %>% dplyr::filter(.data$charge_per > 5),
aes(label = round(.data$charge_per, digits = 1)),
position = position_stack(vjust = 0.9)
data = label_positions,
aes(y = label_y,
label = round(.data$charge_per, digits = 1)),
vjust = 1.5
)
}
} +
labs(
title = "Charge distribution per .raw file",
subtitle = "By percent of total intensity",
x = "Sample",
y = "% of total intensity",
fill = "Charge"
) +
theme_bw() +
theme(
plot.title = ggplot2::element_text(size = 20),
axis.title.x = ggplot2::element_text(size = 15),
axis.title.x = ggplot2::element_blank(),
axis.text.y = ggplot2::element_text(size = 15),
axis.text.x = ggplot2::element_text(size = 12, angle = 75, hjust = 1),
axis.title.y = ggplot2::element_text(size = 15),
Expand Down
65 changes: 40 additions & 25 deletions R/qc_missed_cleavages.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#' @export
#'
#' @examples
#' library(dplyr)
#'
#' set.seed(123) # Makes example reproducible
#'
#' # Create example data
Expand All @@ -49,15 +51,16 @@
#' n_replicates = 3,
#' n_conditions = 2,
#' method = "effect_random"
#' )
#' ) %>%
#' mutate(intensity_non_log2 = 2^peptide_intensity_missing)
#'
#' # Calculate missed cleavage percentages
#' qc_missed_cleavages(
#' data = data,
#' sample = sample,
#' grouping = peptide,
#' missed_cleavages = n_missed_cleavage,
#' intensity = peptide_intensity_missing,
#' intensity = intensity_non_log2,
#' method = "intensity",
#' plot = FALSE
#' )
Expand All @@ -68,7 +71,7 @@
#' sample = sample,
#' grouping = peptide,
#' missed_cleavages = n_missed_cleavage,
#' intensity = peptide_intensity_missing,
#' intensity = intensity_non_log2,
#' method = "intensity",
#' plot = TRUE
#' )
Expand Down Expand Up @@ -113,6 +116,12 @@ intensities or set remove_na_intensities to FALSE",
))
}

label_positions <- result %>%
dplyr::group_by({{ sample }}) %>%
dplyr::arrange(desc({{ missed_cleavages }})) %>%
dplyr::mutate(label_y = cumsum(.data$mc_percent)) %>%
dplyr::filter(.data$mc_percent > 5)

if (plot == FALSE) {
return(result)
} else {
Expand All @@ -122,34 +131,34 @@ intensities or set remove_na_intensities to FALSE",
y = .data$mc_percent,
fill = {{ missed_cleavages }}
)) +
geom_col(col = "black", size = 1) +
ggplot2::geom_col(col = "black", size = 1) +
{
if (interactive == FALSE) {
geom_text(
data = result %>% dplyr::filter(.data$mc_percent > 5),
aes(label = round(.data$mc_percent, digits = 1)),
position = position_stack(vjust = 0.9)
ggplot2::geom_text(
data = label_positions,
aes(y = .data$label_y,
label = round(.data$mc_percent, digits = 1)),
vjust = 1.5
)
}
} +
labs(
ggplot2::labs(
title = "Missed cleavages per .raw file",
subtitle = "By percent of total peptide count",
x = "Sample",
y = "% of total peptide count",
fill = "Missed cleavages"
) +
theme_bw() +
theme(
ggplot2::theme_bw() +
ggplot2::theme(
plot.title = ggplot2::element_text(size = 20),
axis.title.x = ggplot2::element_text(size = 15),
axis.title.x = ggplot2::element_blank(),
axis.text.y = ggplot2::element_text(size = 15),
axis.text.x = ggplot2::element_text(size = 12, angle = 75, hjust = 1),
axis.title.y = ggplot2::element_text(size = 15),
legend.title = ggplot2::element_text(size = 15),
legend.text = ggplot2::element_text(size = 15)
) +
scale_fill_manual(values = protti_colours)
ggplot2::scale_fill_manual(values = protti_colours)
}
}

Expand Down Expand Up @@ -177,6 +186,12 @@ intensities or set remove_na_intensities to FALSE",
))
}

label_positions <- result %>%
dplyr::group_by({{ sample }}) %>%
dplyr::arrange(desc({{ missed_cleavages }})) %>%
dplyr::mutate(label_y = cumsum(.data$mc_percent)) %>%
dplyr::filter(.data$mc_percent > 5)

if (plot == FALSE) {
return(result)
} else {
Expand All @@ -186,34 +201,34 @@ intensities or set remove_na_intensities to FALSE",
y = .data$mc_percent,
fill = {{ missed_cleavages }}
)) +
geom_col(col = "black", size = 1) +
ggplot2::geom_col(col = "black", size = 1) +
{
if (interactive == FALSE) {
geom_text(
data = result %>% dplyr::filter(.data$mc_percent > 5),
aes(label = round(.data$mc_percent, digits = 1)),
position = position_stack(vjust = 0.9)
ggplot2::geom_text(
data = label_positions,
aes(y = .data$label_y,
label = round(.data$mc_percent, digits = 1)),
vjust = 1.5
)
}
} +
labs(
ggplot2::labs(
title = "Missed cleavages per .raw file",
subtitle = "By percent of total intensity",
x = "",
y = "% of total intensity",
fill = "Missed cleavages"
) +
theme_bw() +
theme(
ggplot2::theme_bw() +
ggplot2::theme(
plot.title = ggplot2::element_text(size = 20),
axis.title.x = ggplot2::element_text(size = 15),
axis.title.x = ggplot2::element_blank(),
axis.text.y = ggplot2::element_text(size = 15),
axis.text.x = ggplot2::element_text(size = 12, angle = 75, hjust = 1),
axis.title.y = ggplot2::element_text(size = 15),
legend.title = ggplot2::element_text(size = 15),
legend.text = ggplot2::element_text(size = 15)
) +
scale_fill_manual(values = protti_colours)
ggplot2::scale_fill_manual(values = protti_colours)
}
}
if (interactive == TRUE) {
Expand Down
32 changes: 22 additions & 10 deletions R/qc_peptide_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ qc_peptide_type <- function(data,
))
}

label_positions <- result %>%
dplyr::group_by({{ sample }}) %>%
dplyr::arrange(desc(.data$pep_type)) %>%
dplyr::mutate(label_y = cumsum(.data$peptide_type_percent)) %>%
dplyr::filter(.data$peptide_type_percent > 5)

if (plot == TRUE & interactive == FALSE) {
plot <- result %>%
ggplot2::ggplot(ggplot2::aes(
Expand All @@ -119,9 +125,10 @@ qc_peptide_type <- function(data,
)) +
ggplot2::geom_col(col = "black", size = 1) +
geom_text(
data = result %>% dplyr::filter(.data$peptide_type_percent > 10),
aes(label = round(.data$peptide_type_percent, digits = 1)),
position = position_stack(vjust = 0.9)
data = label_positions,
aes(y = label_y,
label = round(.data$peptide_type_percent, digits = 1)),
vjust = 1.5
) +
ggplot2::labs(
title = "Peptide types per .raw file",
Expand Down Expand Up @@ -198,6 +205,12 @@ qc_peptide_type <- function(data,
))
}

label_positions <- result %>%
dplyr::group_by({{ sample }}) %>%
dplyr::arrange(desc(.data$pep_type)) %>%
dplyr::mutate(label_y = cumsum(.data$peptide_type_percent)) %>%
dplyr::filter(.data$peptide_type_percent > 5)

if (plot == TRUE & interactive == FALSE) {
plot <- result %>%
ggplot2::ggplot(ggplot2::aes(
Expand All @@ -207,20 +220,20 @@ qc_peptide_type <- function(data,
)) +
ggplot2::geom_col(col = "black", size = 1) +
geom_text(
data = result %>% dplyr::filter(.data$peptide_type_percent > 10),
aes(label = round(.data$peptide_type_percent, digits = 1)),
position = position_stack(vjust = 0.9)
data = label_positions,
aes(y = label_y,
label = round(.data$peptide_type_percent, digits = 1)),
vjust = 1.5
) +
ggplot2::labs(
title = "Peptide type intensity per .raw file",
x = "Sample",
y = "Percentage of total peptide intensity",
fill = "Type"
) +
ggplot2::theme_bw() +
ggplot2::theme(
plot.title = ggplot2::element_text(size = 20),
axis.title.x = ggplot2::element_text(size = 15),
axis.title.x = ggplot2::element_blank(),
axis.text.y = ggplot2::element_text(size = 15),
axis.text.x = ggplot2::element_text(size = 12, angle = 75, hjust = 1),
axis.title.y = ggplot2::element_text(size = 15),
Expand All @@ -240,14 +253,13 @@ qc_peptide_type <- function(data,
ggplot2::geom_col(col = "black", size = 1) +
ggplot2::labs(
title = "Peptide type intensity per .raw file",
x = "Sample",
y = "Percentage of total peptide intensity",
fill = "Type"
) +
ggplot2::theme_bw() +
ggplot2::theme(
plot.title = ggplot2::element_text(size = 20),
axis.title.x = ggplot2::element_text(size = 15),
axis.title.x = ggplot2::element_blank(),
axis.text.y = ggplot2::element_text(size = 15),
axis.text.x = ggplot2::element_text(size = 12, angle = 75, hjust = 1),
axis.title.y = ggplot2::element_text(size = 15),
Expand Down

0 comments on commit 0272a72

Please sign in to comment.