Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • #16
    Hey blakeoft and all,

    I am building a barplot (using ggplot) with values for 5 genes (SHP....PHB) side by side on the x axis comparing normalized fold induction on the y axis (for example, the most induced gene is SHP with normalized fold induction of ~30, then NGA1, etc). I have struggled a lot to add the error bars on top of the graph.
    Could anyone please give me a hand with this? Many thanks.

    genes<-factor(c('SHP', 'NGA1', 'PAN', 'TUB', 'PHB'))
    values1<-c(29.77,4.55,3.23,1.28,0.06)
    values2<-c(30.37,3.43,2.07,0.81,4.93)
    df<- data.frame(genes,values1,values2)

    ggplot(data=df,aes(x=genes,y=values1)) + geom_bar(stat='identity') +
    scale_x_discrete(limits=df$genes[order(levels(df$genes))])
    Last edited by Gonza; 11-21-2014, 05:41 PM.

    Comment


    • #17
      Gonza,

      Sorry for the late reply. Can you explain your data a little more? You want to add error bars, but that usually means that you have upper and lower bounds. At first it looks like you want the upper bounds to be values2, but upon closer inspection, most of these numbers are smaller than the corresponding numbers in values1.

      Let's suppose you have two vectors, error.hi and error.lo, that contain upper and lower error bounds, respectively. For the sake of running the code at the end of my post, let's define them as

      Code:
      error.hi <- values1 + 0.5
      error.lo <- values1 - 0.5
      error.lo[error.lo < 0] <- 0
      Then you'd want to run

      Code:
      ggplot(data=df, aes(x = genes,y = values1, fill = genes)) +
          geom_bar(stat = 'identity') +
          scale_x_discrete(limits = df$genes[order(levels(df$genes))]) +
          geom_errorbar(aes(x = genes, ymin = error.lo, ymax = error.hi, width = 0.5))

      Comment


      • #18
        Thanks blakeoft. I actually made a lot of progress since that previous post. I still have one quick question though...

        When i build the graph i cannot organize it in such a way that the genes (on x axis) are arranged from the highest to the lowest values (R automatically orders them by name). Any thoughts on how to order this?

        Thanks again
        -G

        Please see my code:

        #########

        rm (list=ls())
        library(plyr)
        library(ggplot2)
        library(bear)

        # make a data frame called 'df'

        SHP<- c(29.77,30.37)
        NGA1 <- c(4.55,3.43)
        PAN<-c(3.23,2.07)
        TUB<-c(1.28,0.81)

        gene<-as.factor(c("SHP","SHP","NGA1","NGA1","PAN","PAN","TUB","TUB"))
        df<-data.frame(gene,c(SHP,NGA1,PAN,TUB))
        df

        colnames(df)[2]<- "CT_values"

        # summarySE to provide the standard deviation, standard error of the mean, and a (default 95%) confidence interval
        dfc <- summarySE(df, measurevar="CT_values", groupvars=c("gene"))


        ##Plot

        p<- ggplot(dfc, aes(x=gene, y=CT_values, fill=gene)) +
        geom_bar(position=position_dodge(), stat="identity",
        colour="black", # Use black outlines,
        size=.3) + # Thinner lines
        geom_errorbar(aes(ymin=CT_values-se, ymax=CT_values+se),
        size=.3, # Thinner lines
        width=.2,
        position=position_dodge(.9)) +
        xlab("Gene Assayed") +
        ylab("Normalized Fold Enrichment YFP+/YFP-") +
        scale_fill_hue(name="GeneID", # Legend label, use darker colors
        breaks=c("SHP","NGA1","PAN","TUB"),
        labels=c(" SHP","NGA1","PAN","TUB")) +
        ggtitle("mRNAs enriched in the sorted YFP+ protoplasts") +
        scale_y_continuous(breaks=0:20*4) +
        theme_bw()
        p

        ##add label

        label.df <- data.frame(gene = c("NGA1", "SHP"),
        CT_values = c(5,31))
        p + geom_text(data = label.df, label = "*")

        Comment


        • #19
          I'm not able to give you the best answer since I'm not at my work station.

          Have a look at this link though. Please let me know if you're still having trouble after reading.

          http://stackoverflow.com/questions/3...cale-in-ggplot

          Comment


          • #20
            Hi blakeoft,

            After a lot of pain.....it worked! I found this website more helpful.


            Again thank you....

            Comment


            • #21
              Hi Blakeoft

              I have used the suggestion you provided a while ago to get the names of the genes (not only XLOC) when using cummeRbund. I am now wondering if there is there a way to get the genes ID instead of their names? For example, instead of getting SHP2 I'd like to get AT2G42830. Thanks for your help.

              #######

              I have done this (as you suggested before):

              cuff <- readCufflinks()

              #Retrive significant gene IDs (XLOC) with a pre-specified alpha
              diffGeneIDs <- getSig(cuff,level="genes",alpha=0.05)

              #Use returned identifiers to create a CuffGeneSet object with all relevant info for given genes
              diffGenes<-getGenes(cuff,diffGeneIDs)

              #gene_short_name values (and corresponding XLOC_* values) can be retrieved from the CuffGeneSet by using:
              names<-featureNames(diffGenes)
              row.names(names)=names$tracking_id
              diffGenesNames<-as.matrix(names)
              diffGenesNames<-diffGenesNames[,-1]

              # get the data for the significant genes
              diffGenesData<-diffData(diffGenes)
              row.names(diffGenesData)=diffGenesData$gene_id
              diffGenesData<-diffGenesData[,-1]

              # merge the two matrices by row names
              diffGenesOutput<-merge(diffGenesNames,diffGenesData,by="row.names")

              Comment


              • #22
                Gonza,

                There are several different types of gene identifiers. If you have a vector of gene names, you could take them to Ensembl's Biomart. There's also a Bioconductor package that can convert gene names as well. Be aware that mapping from one ID to another isn't always perfect. For example, you might get two Entrez IDs for the same gene symbol, but after looking up those Entrez IDs, you might find that only one of them is the right one for you. Unfortunately, I don't know how to fix that problem.

                Comment


                • #23
                  Thanks Blakeoft, will look into that !
                  G

                  Comment

                  Latest Articles

                  Collapse

                  • seqadmin
                    Strategies for Sequencing Challenging Samples
                    by seqadmin


                    Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                    03-22-2024, 06:39 AM
                  • seqadmin
                    Techniques and Challenges in Conservation Genomics
                    by seqadmin



                    The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

                    Avian Conservation
                    Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
                    03-08-2024, 10:41 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by seqadmin, 03-27-2024, 06:37 PM
                  0 responses
                  13 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 03-27-2024, 06:07 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 03-22-2024, 10:03 AM
                  0 responses
                  53 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 03-21-2024, 07:32 AM
                  0 responses
                  69 views
                  0 likes
                  Last Post seqadmin  
                  Working...
                  X