Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rwan
    Member
    • Feb 2013
    • 11

    #1

    Contents of ballgown object

    Dear all,

    I'm new to ballgown and one of the things I'd like to do is to create a PCA plot using R / ggplot2's ggfortify. I have something like this so far:

    Code:
    pheno_data <- read.csv ("phenodata.csv")
    
    bg = ballgown (...)
    bg_filter = subset (bg, "rowVars (gexpr (bg)) > 1", genomesubset=TRUE)
    y <- log2 (gexpr (bg_filter) + 1)
    pca <- prcomp (t (y))
    
    autoplot (pca)
    and this works nicely, but I'd like to colour the points by sample. For example, see https://cran.r-project.org/web/packa.../plot_pca.html

    As the above web page describes, I can colour it by giving it a "colour = 'Species'" argument...this is a vector which lists the sample names (as a factor).

    Does anyone know what I'm missing? I *think* I'm close...but I'm not sure what I need to do.

    Thank you!

    Ray
  • philipp.bayer
    Junior Member
    • May 2014
    • 2

    #2
    I know this is kind of old, but here's how I solved it (since there's not much else on Google for this solution??)

    Let's say you have a ballgown object by the name of bg, and a table with your conditions named pheno_data:

    Code:
    bg = ballgown(samples=as.vector(sample_full_path),pData=pheno_data)
    
    # run the PCA
    y = log2(texpr(bg)+1)
    pca = prcomp(t(y))
    pcmat = pca$x
    # make a new data frame with the data we want
    pcmat = data.frame(Name=str_replace(rownames(pcmat), 'FPKM.', ''), PC1=pcmat[,1], PC2=pcmat[,2], group=pheno_data$condition)
    
    library(ggrepel)
    library(ggplot2)
    # plot the PCA with nice labels
    ggplot(data=pcmat, aes(x=PC1, y=PC2, colour=group, label=Name)) + geom_point() + geom_label()
    # save the thing
    ggsave('PCA.png', height=15, width=15, unit='cm')
    Then you get a nice PCA plot with labels based on each name (here the individuals' names) colored by their group.

    Comment

    Latest Articles

    Collapse

    • SEQadmin2
      16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
      by SEQadmin2




      NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification, detection...
      10-30-2026, 06:46 AM
    • SEQadmin2
      Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
      by SEQadmin2



      Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

      Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
      ...
      10-14-2026, 09:55 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, 10-28-2026, 09:57 AM
    0 responses
    37 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-28-2026, 09:51 AM
    0 responses
    23 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-22-2026, 11:13 AM
    0 responses
    72 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-22-2026, 10:48 AM
    0 responses
    48 views
    0 reactions
    Last Post SEQadmin2  
    Working...