[R] Plotting Character Variable
Marc Schwartz (via MN)
mschwartz at mn.rr.com
Thu Jul 7 18:37:17 CEST 2005
On Thu, 2005-07-07 at 11:47 -0400, ohalawa at umich.edu wrote:
> Any ideas about the following problem:
> I have a matrix (A) that looks like this:
> gene_names values
> hsa-mir-124 0.3
> hsa-mir-234 0.1
> hsa-mir-344 0.4
> hsa-mir-333 0.7
> ..... .......
> (This is a 2 by 22283 matrix: quite large)
To split hairs, it would be a 22283 by 2 object in R's [row, column]
approach to indexing.
I am also presuming that "A" is a data frame, since you seem to have two
different data types above, with gene_names being a factor?
> I would like to plot the values, but output the gene_names as the plotting
> symbol. I have tried regular x,y plots, but since the gene_names are quite
> large and there are 22283 of them, it's impossible to fit them on the x-axis.
> Basically, can I plot the above matrix
> plot(gene_names, value) where the gene_names are used as the plotting symbol.
> thank you,
I would defer to those with more experience in plotting genetic data,
but from a practical standpoint, it seems to me to be highly problematic
to plot >20,000 data points with labels and have them be human readable
without an STM....unless you have _very_ wide paper on a large format
That being said, one approach is to rotate the x axis labels vertically,
to make more room, while using points for the plotting symbols:
# Adjust bottom margin to make room for vertical labels
par(mar = c(7, 4, 4, 2))
plot(1:nrow(A), A$values, xaxt = "n", ann = FALSE, las = 2)
# use 'las = 3' to rotate the labels
axis(1, at = 1:nrow(A),
labels = as.character(A$gene_names), las = 3)
You might want to review some of the tools available at the Bioconductor
site to see if there are specialized plotting functions for this type of
More information about the R-help