Dot Plot for a matrix
2
0
Entering edit mode
10.1 years ago
dktarathym ▴ 40

I have a matrix.

Dimensions=> rows= 6534, columns= 6

rows are the ORF (yeast)

columns are the name of the vcf files of yeast.

This matrix stores the information of no. of mutations occurring for a particular gene in each file (0 means, there is no mutation of that particular gene in the file)

> head(matrix)
          D784G    DAS217    dst1    E1224G    F1205H    rpa12
Q0010     0        0         0       0         0         4
Q0032     0        0         0       0         0         0
Q0055     1        1         1       1         1         1
Q0075     0        0         0       0         0         0
Q0080     0        0         0       0         0         0
Q0085    15        12        13      10        13        15

I want to make a dot plot:

X-axis= genes, Y-axis= No. of mutations for all 6 files in 6 different colors & shapes. Also, there should be a legend for the 6 files.

I am confused. How to write command for this?

Regards,
Deepak

Bioconductor R • 5.7k views
ADD COMMENT
2
Entering edit mode
10.1 years ago
  1. Use the reshape2 package to convert that matrix to a format with the following columns: Gene (these will repeat once per sample), number of mutations, and sample.
  2. Use ggplot to make the dot plot. If you set colour= to the sample column then it'll generate the legend for you.
ADD COMMENT
0
Entering edit mode

Thank you Devon

ADD REPLY
2
Entering edit mode
10.1 years ago
komal.rathi ★ 4.1k

This is a very direct question to get others to do your homework but I am assuming you have absolutely no background in R because I see no code showing that you at least tried. From hereon, you should work on your R skills. Meanwhile you can use this code:

library(ggplot2)
library(reshape2)

# use melt function to transform your dataset for ggplot2
# it melts your dataset such that first column contains genes, second column has sample names and third column has the mutation value
dat = melt(matrix)
head(dat)

   Var1  Var2 value
1 Q0010 D784G     0
2 Q0032 D784G     0
3 Q0055 D784G     1
4 Q0075 D784G     0
5 Q0080 D784G     0
6 Q0081 D784G    15

# create plot using ggplot function. geom_point() is used for creating dot plots
ggplot(data = dat,aes(x = Var1, y = value)) + 
  geom_point(data = dat,aes(pch = factor(Var2), colour = factor(Var2))) + 
  xlab('Genes') + scale_shape_discrete(name="LegendTitle") + scale_colour_discrete(name="LegendTitle")

Play with the ggplot2 package to understand what each function is doing.

ADD COMMENT
0
Entering edit mode

Thank you Komal for the help. This was a direct question, as I want to make it understandable, what I want. Therefore, I didn't showed any coding. And I am new to Biostars and using R from last few months only.

I did tried with ggplot2 package, but didn't knew about the reshape2 package. Thank you.

ADD REPLY

Login before adding your answer.

Traffic: 1852 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