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)
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.
Use ggplot to make the dot plot. If you set colour= to the sample column then it'll generate the legend for you.
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.
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.
Thank you Devon