[BioC] Bar plots with stacked columns marked with askterisks

Fraser Sim fjsim at buffalo.edu
Fri Aug 7 02:36:00 CEST 2009


Hi,

You could try the text command to place the text. 

barplot(as.matrix(my.dataM),
   main=title,
   legend=rownames,
   col=c(my.dataColour) -> xx

Now, xx contains the x coordinates of the bars in the chart
Your values in 'my.dataM' contains the y coordinates of the bars

Eg. Text(xx[1], 0.819, "Hello") in your example would place the label
"Hello" on the line of the first bar. You could add a little to the y-value
to move it above or below as to your preference or use the adj parameter to
shift it automatically. 

Text accepts vectors for the x, y, and label parameters so you can get
creative to automatically add labels to your plots according to the data.

Hope that helps,
Fraser

-----Original Message-----
From: bioconductor-bounces at stat.math.ethz.ch
[mailto:bioconductor-bounces at stat.math.ethz.ch] On Behalf Of dorothyc
Sent: Thursday, August 06, 2009 8:15 PM
To: r-ug-ottawa at r-project.org; bioconductor at stat.math.ethz.ch
Subject: Re: [BioC] Bar plots with stacked columns marked with askterisks

Hi,

I'm trying to plot bar graphs with stacked columns marked with  
askterisks for certain columns, which follow certain criteria.

I've gotten the stacked bar plots with Data set A (please refer to  
code below and plot attached).  However, I haven't figured how to put  
asterisks on columns based on some extra information (such as "used/ 
unused") as in Data set B i.e.  asterisks at the top of the Index1 and  
Index3 columns.


---- R code ----
title = 'frequency'
filename = 'testdata2.txt'
sample_output = 'sequences'
# read in data
my.data <- read.delim(filename, sep="\t")

# data from second column onward
my.dataM <- my.data[,2:ncol(my.data)]
# rownames in first column
rownames <- my.data[,1]

# define colours for the categories
col 
= 
c 
("red 
","orange 
","yellow 
","green 
","violet 
","cyan","blue","pink","peachpuff","tomato","seagreen","salmon")
my.dataNcol <- ncol(my.data[,2:ncol(my.data)])
my.dataColour <- col[1:my.dataNcol]
# colors() returns all the colours recognized by R

# a bar plot with stacked bars
if  (is.null(sample_output)) {
	pdf( "BarPlot.pdf")
} else {
     pdf(file=paste("BarPlot_", sample_output, ".pdf", sep="")) } 	
barplot(as.matrix(my.dataM),
   main=title,
   legend=rownames,
   col=c(my.dataColour)
)
dev.off()


------Dataset A: data used with code above------
""	"Index1"	"Index2"	"Index3"	
"matched"	0.819	0.174	0.007
"errors"	0.619	0.314	0.067
"unmatched"	0.479	0.385	0.136


------Dataset B: data intended to use -----
--(last row "used/unused" for determining whether to mark column with  
asterisk or not)---
""	"Index1"	"Index2"	"Index3"	
"matched"	0.819	0.174	0.007
"errors"	0.619	0.314	0.067
"unmatched"	0.479	0.385	0.136
"used/unused"	y	n	y

-------

Thanks,
Dorothy





	[[alternative HTML version deleted]]

_______________________________________________
Bioconductor mailing list
Bioconductor at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/bioconductor
Search the archives:
http://news.gmane.org/gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list