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
                    Advancing Precision Medicine for Rare Diseases in Children
                    by seqadmin




                    Many organizations study rare diseases, but few have a mission as impactful as Rady Children’s Institute for Genomic Medicine (RCIGM). “We are all about changing outcomes for children,” explained Dr. Stephen Kingsmore, President and CEO of the group. The institute’s initial goal was to provide rapid diagnoses for critically ill children and shorten their diagnostic odyssey, a term used to describe the long and arduous process it takes patients to obtain an accurate...
                    12-16-2024, 07:57 AM
                  • seqadmin
                    Recent Advances in Sequencing Technologies
                    by seqadmin



                    Innovations in next-generation sequencing technologies and techniques are driving more precise and comprehensive exploration of complex biological systems. Current advancements include improved accessibility for long-read sequencing and significant progress in single-cell and 3D genomics. This article explores some of the most impactful developments in the field over the past year.

                    Long-Read Sequencing
                    Long-read sequencing has seen remarkable advancements,...
                    12-02-2024, 01:49 PM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by seqadmin, 12-17-2024, 10:28 AM
                  0 responses
                  33 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 12-13-2024, 08:24 AM
                  0 responses
                  49 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 12-12-2024, 07:41 AM
                  0 responses
                  34 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 12-11-2024, 07:45 AM
                  0 responses
                  46 views
                  0 likes
                  Last Post seqadmin  
                  Working...
                  X