cafferychen777 / ggpicrust2

Make Picrust2 Output Analysis and Visualization Easier
https://cafferychen777.github.io/ggpicrust2/
Other
91 stars 11 forks source link

pathway_errorbar(): Editing the images generated using pathway error bar plot analysis #63

Open Aristotle1992 opened 8 months ago

Aristotle1992 commented 8 months ago

Hi Chen, I have no issues with the package and I was able to carry out my analysis without having any hitch. However, is it possible to increase the font size of the image generated especially from the pathway error bar plot? In essence is it possible to edit this image using ggplot2? I checked through the documentation and couldn't find any way to go about this. What will be your best guess or ways to resolve this? Below is my code.

for rhizosphere sample

Load metadata as a tibble

data(metadata)

metadata <- read_delim("C:/Microbiome/picrust/rhizo/check/rhizo_metadata.txt", delim = "\t", escape_double = FALSE, trim_ws = TRUE)

make the growing degree days a factor

metadata$Growing_Degree_Days <- as.factor(metadata$Growing_Degree_Days)

Load KEGG pathway abundance

data(kegg_abundance)

kegg_abundance <- ko2kegg_abundance("C:/Microbiome/picrust/rhizo/check/final_rhizo.tsv")

if you use edger or deseq2 it assumes no significance but if you use limma voom it assumes significant

Perform pathway differential abundance analysis (DAA) using ALDEx2 method

daa_results_df <- pathway_daa(abundance = kegg_abundance, metadata = metadata, group = "Growing_Degree_Days", daa_method = "DESeq2", select = NULL, reference = NULL)

Filter results for ALDEx2_Welch's t test method

Please check the unique(daa_results_df$method) and choose one

daa_sub_method_results_df <- daa_results_df[daa_results_df$method == "DESeq2", ]

Annotate pathway results using KO to KEGG conversion

daa_annotated_sub_method_results_df <- pathway_annotation(pathway = "KO", daa_results_df = daa_sub_method_results_df, ko_to_kegg = TRUE)

Generate pathway error bar plot

p_rhizo <- pathway_errorbar(abundance = kegg_abundance, daa_results_df = daa_annotated_sub_method_results_df, Group = metadata$Growing_Degree_Days, p_values_threshold = 0.05, order = "pathway_class", select = c("ko00627", "ko00940", "ko00531", "ko00460", "ko03020", "ko04070", "ko00770"), ko_to_kegg = TRUE, p_value_bar = TRUE, colors = NULL, x_lab = "pathway_name")

p_rhizo

next I will need to plot the heat map and PCA

save the images for rhizo

ggsave("p_rhizo.png", plot = p_rhizo, path = "C:/Manuscript/Images", dpi = 700, width = 15, height = 10, units = c("in"), device = "png")

Thanks

cafferychen777 commented 8 months ago

Hello @Aristotle1992,

You can modify the font size of your plots by adjusting the theme elements in your ggplot2 calls. For instance, if you want to increase the font size of the axis labels, you can modify the axis.text argument in the theme function. Here's an example:

ggplot2::theme(
  axis.text = ggplot2::element_text(size = 12, color = "black"),
  ...
)

In the pathway_errorbar function you provided, there are several places where the theme function is used, and you can adjust the font size in these places as needed. Here are the lines you would need to modify:

In each of these lines, you can increase the size argument to increase the font size. For example, you can change size = 10 to size = 12 to increase the font size.

pathway_errorbar <-
  function(abundance,
           daa_results_df,
           Group,
           ko_to_kegg = FALSE,
           p_values_threshold = 0.05,
           order = "group",
           select = NULL,
           p_value_bar = TRUE,
           colors = NULL,
           x_lab = NULL) {
    # Identify pathways with missing annotation
    missing_pathways <- daa_results_df[is.na(daa_results_df$pathway_name), "feature"]

    # Inform the user about the missing annotations
    if(length(missing_pathways) > 0) {
      message("The following pathways are missing annotations and have been excluded: ",
              paste(missing_pathways, collapse = ", "))
      message("You can use the 'pathway_annotation' function to add annotations for these pathways.")
    }

    # Get the names of all columns in the data frame
    column_names <- colnames(daa_results_df)

    # Check if there are more than two 'group' columns
    group_columns <- grepl("^group", column_names)
    if (sum(group_columns) > 2) {
      p_value_bar <- FALSE
      message(
        "There are more than two 'group' columns in the 'daa_results_df' data frame. As a result, it is not possible to compute the log2 fold values. The 'p_value_bar' has been automatically set to FALSE."
      )
    }

    # Exclude rows with missing pathway annotation
    daa_results_df <- daa_results_df[!is.na(daa_results_df[,x_lab]),]

    if (is.null(x_lab)){
      if (ko_to_kegg == TRUE){
        x_lab <- "pathway_name"
      }else{
        x_lab <- "description"
      }

      if (is.null(daa_results_df$pathway_name)&is.null(daa_results_df$description)){
        message(
          "Please utilize the 'pathway_annotation' function to annotate the 'daa_results_df' data frame."
        )
      }
    }

    if (!(x_lab %in% colnames(daa_results_df))){
      message(
        "The 'x_lab' you defined does not exist as a column in the 'daa_results_df' data frame."
      )
    }

    if (nlevels(factor(daa_results_df$method)) != 1) {
      message(
        "The 'method' column in the 'daa_results_df' data frame contains more than one method. Please filter it to contain only one method."
      )
    }

    if (nlevels(factor(daa_results_df$group1)) != 1 || nlevels(factor(daa_results_df$group2)) != 1) {
      message(
        "The 'group1' or 'group2' column in the 'daa_results_df' data frame contains more than one group. Please filter each to contain only one group."
      )
    }

    if (is.null(colors)) {
      colors <- c("#d93c3e", "#3685bc", "#6faa3e", "#e8a825", "#c973e6", "#ee6b3d", "#2db0a7", "#f25292")[1:nlevels(as.factor(Group))]
    }
    errorbar_abundance_mat <- as.matrix(abundance)
    daa_results_filtered_df <-
      daa_results_df[daa_results_df$p_adjust < p_values_threshold,]
    if (!is.null(select)) {
      daa_results_filtered_sub_df <-
        daa_results_filtered_df[daa_results_filtered_df$feature %in% select, ]
    } else {
      daa_results_filtered_sub_df <- daa_results_filtered_df
    }
    if (nrow(daa_results_filtered_sub_df) > 30) {
      message(
        paste0(
          "The number of features with statistical significance exceeds 30, leading to suboptimal visualization. ",
          "Please use 'select' to reduce the number of features.\n",
          "Currently, you have these features: ",
          paste(paste0('"', daa_results_filtered_sub_df$feature, '"'), collapse = ", "), ".\n",
          "You can find the statistically significant features with the following command:\n",
          "daa_results_df %>% filter(p_adjust < 0.05) %>% select(c(\"feature\",\"p_adjust\"))"
        )
      )
      stop()
    }
    if (nrow(daa_results_filtered_sub_df) == 0){
      stop(
        "Visualization with 'pathway_errorbar' cannot be performed because there are no features with statistical significance. ",
        "For possible solutions, please check the FAQ section of the tutorial."
      )
    }
    # Convert to relative abundance
    relative_abundance_mat <- apply(t(errorbar_abundance_mat), 1, function(x)
      x / sum(x))

    # Subset to only include the features present in daa_results_filtered_sub_df$feature
    sub_relative_abundance_mat <- relative_abundance_mat[rownames(relative_abundance_mat) %in% daa_results_filtered_sub_df$feature,]

    # Create a matrix for the error bars
    error_bar_matrix <- cbind(
      sample = colnames(sub_relative_abundance_mat),
      group = Group,
      t(sub_relative_abundance_mat)
    )
    error_bar_df <- as.data.frame(error_bar_matrix)
    error_bar_df$group <- factor(Group,levels = levels(as.factor(Group)))
      error_bar_pivot_longer_df <- tidyr::pivot_longer(error_bar_df,-c(sample, group))
    error_bar_pivot_longer_tibble <-
      mutate(error_bar_pivot_longer_df, group = as.factor(group))
    error_bar_pivot_longer_tibble$sample <-
      factor(error_bar_pivot_longer_tibble$sample)
    error_bar_pivot_longer_tibble$name <-
      factor(error_bar_pivot_longer_tibble$name)
    error_bar_pivot_longer_tibble$value <-
      as.numeric(error_bar_pivot_longer_tibble$value)
    error_bar_pivot_longer_tibble_summarised <-
      error_bar_pivot_longer_tibble %>% group_by(name, group) %>%
      summarise(mean = mean(value), sd = stats::sd(value))
    error_bar_pivot_longer_tibble_summarised <-
      error_bar_pivot_longer_tibble_summarised %>% mutate(group2 = "nonsense")
    switch(
      order,
      "p_values" = {
        order <- order(daa_results_filtered_sub_df$p_adjust)
      },
      "name" = {
        order <- order(daa_results_filtered_sub_df$feature)
      },
      "group" = {
        daa_results_filtered_sub_df$pro <- 1
        for (i in levels(error_bar_pivot_longer_tibble_summarised$name)) {
          error_bar_pivot_longer_tibble_summarised_sub <-
            error_bar_pivot_longer_tibble_summarised[error_bar_pivot_longer_tibble_summarised$name ==
                                                       i,]
          pro_group <-
            error_bar_pivot_longer_tibble_summarised_sub[error_bar_pivot_longer_tibble_summarised_sub$mean ==
                                                           max(error_bar_pivot_longer_tibble_summarised_sub$mean),]$group
          pro_group <- as.vector(pro_group)
          daa_results_filtered_sub_df[daa_results_filtered_sub_df$feature ==
                                        i,]$pro <- pro_group
        }
        order <-
          order(daa_results_filtered_sub_df$pro,
                daa_results_filtered_sub_df$p_adjust)
      },
      "pathway_class" = {
        if (!"pathway_class" %in% colnames(daa_results_filtered_sub_df)) {
          stop(
            "The 'pathway_class' column is missing in the 'daa_results_filtered_sub_df' data frame. ",
            "Please use the 'pathway_annotation' function to annotate the 'pathway_daa' results."
          )
        }
        order <- order(
          daa_results_filtered_sub_df$pathway_class,
          daa_results_filtered_sub_df$p_adjust
        )
      },
      {
        order <- order
      }
    )
    daa_results_filtered_sub_df <-
      daa_results_filtered_sub_df[order,]
    error_bar_pivot_longer_tibble_summarised_ordered <-
      data.frame(
        name = NULL,
        group = NULL,
        mean = NULL,
        sd = NULL
      )
    for (i in daa_results_filtered_sub_df$feature) {
      error_bar_pivot_longer_tibble_summarised_ordered <-
        rbind(
          error_bar_pivot_longer_tibble_summarised_ordered,
          error_bar_pivot_longer_tibble_summarised[error_bar_pivot_longer_tibble_summarised$name ==
                                                     i,]
        )
    }
    if (ko_to_kegg == FALSE){
      error_bar_pivot_longer_tibble_summarised_ordered[, x_lab] <-
        rep(daa_results_filtered_sub_df[, x_lab], each = length(levels(
          factor(error_bar_pivot_longer_tibble_summarised_ordered$group)
        )))
    }

    if (ko_to_kegg == TRUE) {
      error_bar_pivot_longer_tibble_summarised_ordered$pathway_class <-
        rep(daa_results_filtered_sub_df$pathway_class,
            each = length(levels(
              factor(error_bar_pivot_longer_tibble_summarised_ordered$group)
            )))
    }
    error_bar_pivot_longer_tibble_summarised_ordered$name <- factor(error_bar_pivot_longer_tibble_summarised_ordered$name, levels = rev(daa_results_filtered_sub_df$feature))

    bar_errorbar <-
      ggplot2::ggplot(error_bar_pivot_longer_tibble_summarised_ordered, # nolint: object_usage_linter.
             ggplot2::aes(mean, name, fill = group)) + # nolint
      ggplot2::geom_errorbar(
        ggplot2::aes(xmax = mean + sd, xmin = 0),
        position = ggplot2::position_dodge(width = 0.8),
        width = 0.5,
        size = 0.5,
        color = "black"
      ) +
      ggplot2::geom_bar(stat = "identity",
               position = ggplot2::position_dodge(width = 0.8),
               width = 0.8) +
      GGally::geom_stripped_cols(width = 10) +
      ggplot2::scale_fill_manual(values = colors) +
      ggplot2::scale_color_manual(values = colors) +
      ggprism::theme_prism() +
      ggplot2::scale_x_continuous(expand = c(0, 0),
                         guide = "prism_offset_minor",) +
      ggplot2::scale_y_discrete(labels = rev(daa_results_filtered_sub_df[, x_lab])) +
      ggplot2::labs(x = "Relative Abundance", y = NULL) +
      ggplot2::theme(
        axis.ticks.y = ggplot2::element_blank(),
        axis.line.y = ggplot2::element_blank(),
        axis.line.x = ggplot2::element_line(size = 0.5),
        axis.ticks.x = ggplot2::element_line(size = 0.5),
        panel.grid.major.y = ggplot2::element_blank(),
        panel.grid.major.x = ggplot2::element_blank(),
        axis.text = ggplot2::element_text(size = 10, color = "black"), # nolint
        axis.text.x = ggplot2::element_text(margin = ggplot2::margin(r = 0)), # nolint
        axis.text.y = ggplot2::element_text(
          size = 10,
          color = "black",
          margin = ggplot2::margin(b = 6)
        ),
        axis.title.x =  ggplot2::element_text(
          size = 10,
          color = "black",
          hjust = 0.5
        ),
        legend.position = "top",
        legend.key.size = ggplot2::unit(0.1, "cm"),
        legend.direction = "vertical",
        legend.justification = "left",
        legend.text = ggplot2::element_text(size = 8, face = "bold"),
        legend.box.just = "right",
        plot.margin = ggplot2::margin(0, 0.5, 0.5, 0, unit = "cm")
      ) + ggplot2::coord_cartesian(clip = "off")

    if (ko_to_kegg == TRUE) {
      pathway_class_group_mat <-
        daa_results_filtered_sub_df$pathway_class %>%
        table() %>%
        data.frame() %>% column_to_rownames(".")
      pathway_class_group <- data.frame(.= unique(daa_results_filtered_sub_df$pathway_class),Freq = pathway_class_group_mat[unique(daa_results_filtered_sub_df$pathway_class),])
      start <-
        c(1, rev(pathway_class_group$Freq)[1:(length(pathway_class_group$Freq) - 1)]) %>%
        cumsum()
      end <- cumsum(rev(pathway_class_group$Freq))
      ymin <- start - 1 / 2
      ymax <- end + 1 / 2
      nPoints <- length(start)
      pCol <- c("#D51F26","#272E6A","#208A42","#89288F","#F47D2B",
                 "#FEE500","#8A9FD1","#C06CAB","#E6C2DC","#90D5E4",
                 "#89C75F","#F37B7D","#9983BD","#D24B27","#3BBCA8",
                 "#6E4B9E","#0C727C", "#7E1416","#D8A767","#3D3D3D")[1:nPoints]
      pFill <- pCol
      for (i in 1:nPoints)  {
        bar_errorbar <- bar_errorbar +
          ggplot2::annotation_custom(
            grob = grid::rectGrob(
              gp = grid::gpar(
                col = pCol[i],
                fill = pFill[i],
                lty = NULL,
                lwd = NULL,
                alpha = 0.2
              )
            ),
            xmin = ggplot2::unit(-2, 'native'),
            xmax = ggplot2::unit(0, 'native'),
            ymin = ggplot2::unit(ymin[i], 'native'),
            ymax = ggplot2::unit(ymax[i], 'native')
          )
      }
    }
    daa_results_filtered_sub_df <-
      cbind(
        daa_results_filtered_sub_df,
        negative_log10_p = -log10(daa_results_filtered_sub_df$p_adjust),
        group_nonsense = "nonsense",
        log_2_fold_change = NA
      )

    for (i in daa_results_filtered_sub_df$feature){
      mean <- error_bar_pivot_longer_tibble_summarised_ordered[error_bar_pivot_longer_tibble_summarised_ordered$name %in% i,]$mean
      daa_results_filtered_sub_df[daa_results_filtered_sub_df$feature==i,]$log_2_fold_change <- log2(mean[1]/mean[2])
    }
    daa_results_filtered_sub_df$feature <- factor(daa_results_filtered_sub_df$feature,levels = rev(daa_results_filtered_sub_df$feature))
    p_values_bar <- daa_results_filtered_sub_df %>%
      ggplot2::ggplot(ggplot2::aes(feature, log_2_fold_change, fill = group_nonsense)) +
      ggplot2::geom_bar(stat = "identity",
               position = ggplot2::position_dodge(width = 0.8),
               width = 0.8) +
      ggplot2::labs(y = "log2 fold change", x = NULL) +
      GGally::geom_stripped_cols() +
      ggplot2::scale_fill_manual(values = "#87ceeb") +
      ggplot2::scale_color_manual(values = "#87ceeb") +
      ggplot2::geom_hline(ggplot2::aes(yintercept = 0),
                 linetype = 'dashed',
                 color = 'black') +
      ggprism::theme_prism() +
      ggplot2::scale_y_continuous(expand = c(0, 0),
                         guide = "prism_offset_minor") +
      ggplot2::theme(
        axis.ticks.y = ggplot2::element_blank(),
        axis.line.y = ggplot2::element_blank(),
        axis.line.x = ggplot2::element_line(size = 0.5),
        axis.ticks.x = ggplot2::element_line(size = 0.5),
        panel.grid.major.y = ggplot2::element_blank(),
        panel.grid.major.x = ggplot2::element_blank(),
        axis.text = ggplot2::element_text(size = 10, color = "black"),
        axis.text.y = ggplot2::element_blank(),
        axis.text.x = ggplot2::element_text(
          size = 10,
          color = "black",
          margin = ggplot2::margin(b = 6)
        ),
        axis.title.x =  ggplot2::element_text(
          size = 11,
          color = "black",
          hjust = 0.5
        ),
        legend.position = "non"
      ) +
      ggplot2::coord_flip()

    if (ko_to_kegg == TRUE) {
      pathway_class_y <- (ymax + ymin) / 2 - 0.5
      pathway_class_plot_df <-
        as.data.frame(
          cbind(
            nonsense = "nonsense",
            pathway_class_y = pathway_class_y,
            pathway_class = rev(unique(
              daa_results_filtered_sub_df$pathway_class
            ))
          )
        )
      pathway_class_plot_df$pathway_class_y <-
        as.numeric(pathway_class_plot_df$pathway_class_y)
      pathway_class_annotation <-
        pathway_class_plot_df %>% ggplot2::ggplot(ggplot2::aes(nonsense, pathway_class_y)) + ggplot2::geom_text(
          ggplot2::aes(nonsense, pathway_class_y, label = pathway_class),
          size = 3.5,
          color = "black",
          fontface = "bold",
          family = "sans"
        ) +
        ggplot2::scale_y_discrete(position = "right") +
        ggprism::theme_prism() +
        ggplot2::theme(
          axis.ticks = ggplot2::element_blank(),
          axis.line = ggplot2::element_blank(),
          panel.grid.major.y = ggplot2::element_blank(),
          panel.grid.major.x = ggplot2::element_blank(),
          panel.background = ggplot2::element_blank(),
          axis.text = ggplot2::element_blank(),
          plot.margin = ggplot2::unit(c(0, 0.2, 0, 0), "cm"),
          axis.title.y =  ggplot2::element_blank(),
          axis.title.x = ggplot2::element_blank(),
          legend.position = "non"
        )
    }
    daa_results_filtered_sub_df$p_adjust <-
      as.character(daa_results_filtered_sub_df$p_adjust)
    daa_results_filtered_sub_df$unique <-
      nrow(daa_results_filtered_sub_df) - seq_len(nrow(daa_results_filtered_sub_df)) + 1
    daa_results_filtered_sub_df$p_adjust <-
      substr(daa_results_filtered_sub_df$p_adjust, 1, 5)
    p_annotation <- daa_results_filtered_sub_df %>%
      ggplot2::ggplot(ggplot2::aes(group_nonsense, p_adjust)) +
      ggplot2::geom_text(
        ggplot2::aes(group_nonsense, unique, label = p_adjust),
        size = 3.5,
        color = "black",
        fontface = "bold",
        family = "sans"
      ) +
      ggplot2::labs(y = "p-value (adjusted)") +
      ggplot2::scale_y_discrete(position = "right") +
      ggprism::theme_prism() +
      ggplot2::theme(
        axis.ticks = ggplot2::element_blank(),
        axis.line = ggplot2::element_blank(),
        panel.grid.major.y = ggplot2::element_blank(),
        panel.grid.major.x = ggplot2::element_blank(),
        panel.background = ggplot2::element_blank(),
        axis.text = ggplot2::element_blank(),
        plot.margin = ggplot2::unit(c(0, 0.2, 0, 0), "cm"),
        axis.title.y =  ggplot2::element_text(
          size = 11,
          color = "black",
          vjust = 0
        ),
        axis.title.x = ggplot2::element_blank(),
        legend.position = "non"
      )
    if (p_value_bar == TRUE) {
      if (ko_to_kegg == TRUE) {
        combination_bar_plot <-
          pathway_class_annotation + bar_errorbar + p_values_bar + p_annotation + patchwork::plot_layout(ncol = 4, widths =
                                                                                                c(1, 1.2, 0.5, 0.1))
      }
      else{
        combination_bar_plot <-
          bar_errorbar + p_values_bar + p_annotation + patchwork::plot_layout(ncol = 3, widths = c(2.3, 0.7, 0.3))
      }
    }else{
      if (ko_to_kegg == TRUE) {
        combination_bar_plot <-
          pathway_class_annotation + bar_errorbar + p_annotation + patchwork::plot_layout(ncol = 3, widths =
                                                                                                           c(1, 1.2, 0.1))
      }
      else{
        combination_bar_plot <-
          bar_errorbar + p_annotation + patchwork::plot_layout(ncol = 2, widths = c(2.5,  0.2))
      }
    }
    return(combination_bar_plot)
  }

Please note that this will only increase the font size of the text elements specified. If you want to increase the font size of other elements (like the title, legend, etc.), you will need to adjust the corresponding theme arguments.

I hope this helps! Let me know if you have any other questions.

Aristotle1992 commented 8 months ago

Oh, Thanks so much I will try this out.

Aristotle1992 commented 8 months ago

Hi Chen, I can't seem to find my way into increasing the text size. After I have generated the error bar plot graph, do I need to run the following code provided in order to change the font size? I am a bit confused. The code seems lengthy, at what point do I use the ggplot2 to edit the font size?

The code below is what i used to genrate my pathway error bar plot: p_stalk <- pathway_errorbar(abundance = kegg_abundance, daa_results_df = daa_annotated_sub_method_results_df, Group = metadata$Growing_Degree_Days, p_values_threshold = 0.05, order = "pathway_class", select = c("ko00564", "ko00195", "ko00190", "ko00945", "ko00040", "ko03013", "ko00970", "ko03020", "ko00930"), ko_to_kegg = TRUE, p_value_bar = TRUE, colors = NULL, x_lab = "pathway_name")

p_stalk

I need clarity. Thanks

Aristotle1992 commented 8 months ago

This is the code I used:

metadata <- read_delim("C:/Microbiome/picrust/rhizo/check/rhizo_metadata.txt", delim = "\t", escape_double = FALSE, trim_ws = TRUE)

metadata$Growing_Degree_Days <- as.factor(metadata$Growing_Degree_Days)

kegg_abundance <- ko2kegg_abundance("C:/Microbiome/picrust/rhizo/check/final_rhizo.tsv")

daa_results_df <- pathway_daa(abundance = kegg_abundance, metadata = metadata, group = "Growing_Degree_Days", daa_method = "DESeq2", select = NULL, reference = NULL)

daa_sub_method_results_df <- daa_results_df[daa_results_df$method == "DESeq2", ]

daa_annotated_sub_method_results_df <- pathway_annotation(pathway = "KO", daa_results_df = daa_sub_method_results_df, ko_to_kegg = TRUE)

p_rhizo <- pathway_errorbar(abundance = kegg_abundance, daa_results_df = daa_annotated_sub_method_results_df, Group = metadata$Growing_Degree_Days, p_values_threshold = 0.05, order = "pathway_class", select = c("ko00627", "ko00940", "ko00531", "ko00460", "ko03020", "ko04070", "ko00770"), ko_to_kegg = TRUE, p_value_bar = TRUE, colors = NULL, x_lab = "pathway_name")

p_rhizo

The link to the two files used for the analysis is : https://drive.google.com/drive/folders/1MHmbHfWGLRpYpqXYUBqjK9WaAa8ZJztQ?usp=drive_link

cafferychen777 commented 8 months ago

Hi @Aristotle1992,

To address your issue with text size:

  1. First, modify the size parameter inside the pathway_errorbar function, where it's relevant.
  2. Once you've made the necessary adjustments to pathway_errorbar, run the modified function definition again to ensure it's updated with the new parameters.
  3. Now, generate your plot again using the code you provided.

This should solve your text size issue. Let me know if you have any more questions or if there's anything else I can assist you with.

Best regards, Chen

Aristotle1992 commented 8 months ago

I tried the following function as your directed but didnt work out: p_rhizo <- pathway_errorbar(abundance = kegg_abundance, daa_results_df = daa_annotated_sub_method_results_df, Group = metadata$Growing_Degree_Days, p_values_threshold = 0.05, order = "pathway_class", select = c("ko00627", "ko00940", "ko00531", "ko00460", "ko03020", "ko04070", "ko00770"), ko_to_kegg = TRUE, p_value_bar = TRUE, colors = NULL, x_lab = "pathway_name", size = 20)

and this also

p_rhizo_2 <- p_rhizo + theme(text = element_text(size = 40))

p_rhizo_2

None worked for me.

Aristotle1992 commented 8 months ago

Apparently based on the ggpicrust2 documentation, the pathway error function provided does not include the size parameter or any other function to edit the size parameter. How can i resolve this.

cafferychen777 commented 8 months ago

I've already provided explicit instructions in my previous message. Read it thoroughly. If you can't comprehend, use ChatGPT for clarity. Don't make arbitrary modifications and then expect me to fix the resulting issues.

  1. Important Clarification: I did not advise you to directly modify the size parameter in the pathway_errorbar function, simply because it doesn't possess such a parameter. Also, attempting to use p_rhizo + theme(text = element_text(size = 40)) will be ineffective.

  2. Recommended Changes: You should focus on adjusting the size parameters within the specific lines of the theme settings. Here are the lines you need to pay attention to:

- Line 239: `axis.text = ggplot2::element_text(size = 10, color = "black")`
- Line 241: `axis.text.y = ggplot2::element_text(size = 10, color = "black", margin = ggplot2::margin(b = 6))`
- Line 244: `axis.title.x =  ggplot2::element_text(size = 10, color = "black", hjust = 0.5)`
- Line 249: `axis.text = ggplot2::element_text(size = 10, color = "black")`
- Line 252: `axis.text.x = ggplot2::element_text(size = 10, color = "black", margin = ggplot2::margin(b = 6))`
- Line 255: `axis.title.x =  ggplot2::element_text(size = 11, color = "black", hjust = 0.5)`
- Line 312: `axis.text = ggplot2::element_text(size = 10, color = "black")`
- Line 315: `axis.text.x = ggplot2::element_text(size = 10, color = "black", margin = ggplot2::margin(b = 6))`
- Line 318: `axis.title.y =  ggplot2::element_text(size = 11, color = "black", vjust = 0)`

Adjust the size values in these lines as required for your visualization.

Please let me know if there's anything else you'd like assistance with.

Aristotle1992 commented 8 months ago

My apologies. My R skill isnt top notch for now. I wasn't sure if I had to rerun the whole analysis from the code you provided. In anyways I will try to export the table and include it as a supplementary file in my manuscript or possibly find someone who can help out better. Thanks for your responses.

Aristotle1992 commented 7 months ago

Hi Chen, Still, on my quest to increase the font size of the image produced by pathway_errorbar, I forked the ggpicrust2 R source code, edited the script where necessary, and used devtools::install_github("Aristotle1992/ggpicrust2",repos = NULL). However, I got the following error:

devtools::install_github("Aristotle1992/ggpicrust2",repos = NULL) Downloading GitHub repo Aristotle1992/ggpicrust2@HEAD Skipping 20 packages not available: circlize, patchwork, ggprism, tidyr, tibble, SummarizedExperiment, readr, MicrobiomeStat, metagenomeSeq, Maaslin2, limma, lefser, ggh4x, ggplot2, GGally, edgeR, dplyr, DESeq2, aplot, ALDEx2 ── R CMD build ──────────────────────────────────────────────────────────────────────────────────────────── ✔ checking for file 'C:\Users\amoar\AppData\Local\Temp\RtmpCabHUD\remotes1e58420e24aa\Aristotle1992-ggpicrust2-d2c3c47/DESCRIPTION' ... ─ preparing 'ggpicrust2': (672ms) ✔ checking DESCRIPTION meta-information ... ─ checking for LF line-endings in source and make files and shell scripts ─ checking for empty or unneeded directories NB: this package now depends on R (>= 3.5.0) WARNING: Added dependency on R >= 3.5.0 because serialized objects in serialize/load version 3 cannot be read in older versions of R. File(s) containing such objects: 'ggpicrust2/data/daa_annotated_results_df.RData' 'ggpicrust2/data/daa_results_df.RData' 'ggpicrust2/data/kegg_abundance.RData' 'ggpicrust2/data/ko_abundance.RData' 'ggpicrust2/data/metacyc_abundance.RData' 'ggpicrust2/data/metadata.RData' 'ggpicrust2/inst/extdata/EC_reference.RData' 'ggpicrust2/inst/extdata/KO_reference.RData' 'ggpicrust2/inst/extdata/MetaCyc_reference.RData' 'ggpicrust2/inst/extdata/kegg_reference.RData' ─ building 'ggpicrust2_1.7.3.tar.gz'

Installing package into ‘C:/Users/amoar/AppData/Local/R/win-library/4.3’ (as ‘lib’ is unspecified) ERROR: dependencies 'lefser', 'Maaslin2' are not available for package 'ggpicrust2'

Is there any way to resolve this? As a side note, I don't know what this error: ERROR: dependencies 'lefser', 'Maaslin2' are not available for package 'ggpicrust2' means. Thanks

cafferychen777 commented 7 months ago

Dear @Aristotle1992,

It looks like you're encountering an error because the dependencies 'lefser' and 'Maaslin2' are not available in the CRAN repository and need to be installed from Bioconductor. Please try installing these packages separately using the following Bioconductor installation method before installing ggpicrust2:

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("lefser")
BiocManager::install("Maaslin2")

After installing these dependencies, you can try installing ggpicrust2 from GitHub again:

devtools::install_github("Aristotle1992/ggpicrust2")

This should resolve the dependency errors you're facing. If you encounter any further issues, please don't hesitate to reach out.

Best regards,

Chen YANG

Aristotle1992 commented 7 months ago

Hi Chen.

Finally, I was able to increase the font size by forking your source code.

Thanks for your help and prompt response.