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

                  • mylaser
                    Reply to Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                    by mylaser
                    Kheloyar – Everything You Need to Know About Kheloyaar Login and Kheoyar Id
                    If you are looking for an online gaming platform that offers a user-friendly experience, Kheloyar has become a name that many users search for. Whether you're interested in creating a new account, accessing your dashboard through Kheloyaar Login, or learning how to obtain a Kheoyar Id, understanding the platform's features and account process is essential.
                    This guide explains everything you need to know about...
                    Today, 01:13 AM
                  • SEQadmin2
                    Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                    by SEQadmin2



                    Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                    ...
                    07-09-2026, 11:10 AM
                  • SEQadmin2
                    Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                    by SEQadmin2



                    Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                    There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                    07-08-2026, 05:17 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, 07-09-2026, 10:04 AM
                  0 responses
                  17 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-08-2026, 10:08 AM
                  0 responses
                  10 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-07-2026, 11:05 AM
                  0 responses
                  22 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-02-2026, 11:08 AM
                  0 responses
                  31 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...