Plotting the expression of some genes across time points
3
2
Entering edit mode
6.6 years ago

Hi,

I have 8 lists of differential expressed genes between 2-2 h, 4-4h, ..., 16h-16h for two datasets, I mean I have compared time points between datasets. how I can plot the expression of these 8 list across time points???

RNA-seq R Differential expression • 3.7k views
ADD COMMENT
1
Entering edit mode

facet them. I guess you can plot either for a single or set of genes. If you could give us more details about experiment design.

ADD REPLY
0
Entering edit mode

Thanks a lot, supposing 8 lists of genes each list contains differentially expressed for 2h, 24, 6h, 8h, 10h, 12h, 14h, 16h time points, I want to plot a trajectory of expression of these genes across time points. The problem is this, the genes inside these lists are not the same although with some overlap because I have done differential expression analysis separately for each time point. So I want to have plot on the change of expression of these genes across time points, something like terajectories

ADD REPLY
2
Entering edit mode

some thing like this: I copied data frame code from Kevin (from below) and plotted data for 10 genes only. Connected the expression data between two points.

## Create data frame - code from Kevin's post below
x <- data.frame(replicate(10, sample(0:500, 50, replace=TRUE)))
rownames(x) <- paste("gene", c(1:nrow(x)), sep="")
colnames(x)[seq(1,ncol(x), 2)] <- paste("treated.Month", c(1:(ncol(x)/2)), sep="")
colnames(x)[seq(2,ncol(x), 2)] <- paste("untreated.Month", c(1:(ncol(x)/2)), sep="")

## From here on my code
   ## convert rows to id column
     x$id=row.names(x)

   ## wide to long format conversion of df
    library(tidyverse)
    gx=gather(x,"treatment","Expression",-id)

    ## Split the conditions on time and condtion
    library(stringr)
    gx[,c("condition","time")]=str_split_fixed(gx$treatment,"\\.",2)

    ## convert to factor
    gx$time=as.factor(gx$time)
    gx$condition=as.factor(gx$condition)

     ## Extract any 6 genes  as example  (in this case head)
     x10=subset(gx,gx$id %in% head(gx$id))

    ## Plot the expression data
  library(ggplot2)
  ggplot(x10, aes(id, Expression,  color = condition)) +
    geom_point(size = 4) +
    geom_line(aes(group = id), color = "brown", size = 1) +
    facet_wrap(~ time, nrow = 1, ncol = 5) +
    geom_text(aes(label = condition), hjust = 1.2, vjust = 1) +
    theme_bw() +
    theme(legend.position = "none",
          axis.text.x = element_text(angle = 90, size = 17),
          axis.text.y = element_text(size = 17),
          axis.title.x = element_blank(),
          strip.text.x = element_text(size = 15)
          )

output: Rplot01

ADD REPLY
1
Entering edit mode
6.6 years ago
Tm ★ 1.1k

You can represent the expression across all samples by mean of heatmap which in turn can be generated using different softwares like

  • R heatmap.2 package
  • MultiExperiment Viewer (MeV)
  • corrplot package
ADD COMMENT
1
Entering edit mode
6.6 years ago

Feel free to utilise this function, the original 'bare bones' of which was written by a colleague (AKA 'Rana') and then modified by me. This comes with absolutely no warranty. Feel free to edit as you please. It requires ggplot2 and reshape.

1, create some random time-point data

x <- data.frame(replicate(10, sample(0:500, 50, replace=TRUE)))
rownames(x) <- paste("gene", c(1:nrow(x)), sep="")
colnames(x)[seq(1,ncol(x), 2)] <- paste("treated.Month", c(1:(ncol(x)/2)), sep="")
colnames(x)[seq(2,ncol(x), 2)] <- paste("untreated.Month", c(1:(ncol(x)/2)), sep="")
x[1:5,]
      treated.Month1 untreated.Month1 treated.Month2 untreated.Month2
gene1            413              455            120              249
gene2            316               48            194              419
gene3            190              147            404               95
gene4            345              465            427              394
gene5             17              226             31               38
      treated.Month3 untreated.Month3 treated.Month4 untreated.Month4
gene1              9              393            331              462
gene2            300              257            180              294
gene3            395              411            344              229
gene4            159              321            371               42
gene5            213              461            176              480
      treated.Month5 untreated.Month5
gene1            452              394
gene2            410              116
gene3             13              425
gene4            254               51
gene5             88              103

2, create the function

bipartite <- function(x, col1, col2, colour, title, premean, postmean, xlab, ylab, yMin, yMax)
{
    require(ggplot2)
    require(reshape2)

    mydf <- x[,c(col1,col2)]
    mydf$sampleID <- rownames(x)

    #melt dataframe
    mydf<- melt(mydf, id.vars="sampleID", variable.name="var", value.name="value")

    #plotting in ggplot2
    graph <- ggplot(data=mydf, aes(x=var, y=value, group=sampleID)) +

        geom_line(size=0.3) +

        geom_point(size=2.5, shape=21, fill=colour, colour='black') +

        xlab(xlab) + ylab(ylab) +

        ylim(yMin, yMax) +

        #Set the size of the plotting window
        #theme_bw(base_size=24) +

        #Modify various aspects of the plot text and legend
        theme(
            legend.position="none",
            legend.background=element_rect(),
            plot.title=element_text(angle=0, size=12, face="bold", vjust=1),

            axis.text.x=element_text(angle=0, size=12, face="bold", vjust=0.5),
            axis.text.y=element_text(angle=0, size=12, vjust=0.5),
            axis.title=element_text(size=12),

            #Legend
            legend.key=element_blank(),     #removes the border
            legend.key.size=unit(1, "cm"),      #Sets overall area/size of the legend
            legend.text=element_text(size=12),  #Text size
            title=element_text(size=12)) +      #Title text size

        ggtitle(title) +

        geom_hline(yintercept=30, colour="red", size=1.25, linetype="solid") +
        geom_hline(yintercept=premean, colour="grey2", size=0.75, linetype="dotted") +
        geom_hline(yintercept=postmean, colour="grey2", size=0.75, linetype="dotdash")
    return(graph)
}

3, call the function

bipartite(x=x, col1="untreated.Month1", col2="treated.Month1",

    col="black", title="Untreated Vs. Treated\nMonth 1",

    premean=mean(x[,"untreated.Month1"], na.rm=TRUE),

    postmean=mean(x[,"treated.Month1"], na.rm=TRUE),

    xlab="Group and Timepoint", ylab="Expression",

    yMin=0, yMax=max(x, na.rm=TRUE))

f

The dashed line is the mean in the first time-point; the red line is the mean in the second. You can modify these in the code.

Kevin

ADD COMMENT
0
Entering edit mode
6.6 years ago

Try out complexheatmap package

ADD COMMENT

Login before adding your answer.

Traffic: 1142 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6