Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Gonza
    Member
    • Mar 2013
    • 78

    #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

    • blakeoft
      Member
      • Oct 2013
      • 79

      #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

      • Gonza
        Member
        • Mar 2013
        • 78

        #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

        • blakeoft
          Member
          • Oct 2013
          • 79

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

          I am making a dodged bar chart using ggplot with discrete x scale, the x axis are now arranged in alphabetical order, but I need to rearrange it so that it is ordered by the value of the y-axis (i....

          Comment

          • Gonza
            Member
            • Mar 2013
            • 78

            #20
            Hi blakeoft,

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


            Again thank you....

            Comment

            • Gonza
              Member
              • Mar 2013
              • 78

              #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

              • blakeoft
                Member
                • Oct 2013
                • 79

                #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

                • Gonza
                  Member
                  • Mar 2013
                  • 78

                  #23
                  Thanks Blakeoft, will look into that !
                  G

                  Comment

                  Latest Articles

                  Collapse

                  • SEQadmin2
                    From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
                    by SEQadmin2


                    Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


                    The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
                    ...
                    06-02-2026, 10:05 AM
                  • SEQadmin2
                    Single-Cell Sequencing at an Inflection Point: Early Impacts of New Platforms and Emerging Trends
                    by SEQadmin2


                    With the launch of new single-cell sequencing platforms in 2026, the field stands at an exciting inflection point. This article surveys the most impactful advances in the field and discusses how they’re reshaping research in cancer, immunology, and beyond.


                    Introduction

                    Single-cell sequencing technologies have undergone remarkable advances over the past decade, transitioning from low-throughput experimental approaches to highly scalable platforms capable of...
                    05-22-2026, 06:42 AM
                  • SEQadmin2
                    Environmental Genomics in the Age of NGS: From Microbes to Conservation Strategies
                    by SEQadmin2

                    Studying ecosystems means dealing with complex, multi-species communities that are hard to observe at scale. This complexity, however, hides many important questions to be answered, from how biogeochemical cycles work and how climate change can affect species distribution to how conservation strategies can work best.


                    Genomics, particularly since the expansion of NGS, has transformed ecosystem ecology. By sequencing environmental DNA, we can now assess biodiversity without direct...
                    05-06-2026, 09:04 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, Yesterday, 08:59 AM
                  0 responses
                  13 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 06-02-2026, 12:03 PM
                  0 responses
                  21 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 06-02-2026, 11:40 AM
                  0 responses
                  19 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 05-28-2026, 11:40 AM
                  0 responses
                  31 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...