Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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

    • seqadmin
      Essential Discoveries and Tools in Epitranscriptomics
      by seqadmin


      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist on Modified Bases...
      Yesterday, 07:01 AM
    • seqadmin
      Current Approaches to Protein Sequencing
      by seqadmin


      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
      04-04-2024, 04:25 PM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, 04-11-2024, 12:08 PM
    0 responses
    39 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 10:19 PM
    0 responses
    41 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 09:21 AM
    0 responses
    35 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-04-2024, 09:00 AM
    0 responses
    55 views
    0 likes
    Last Post seqadmin  
    Working...
    X