[R] Bar chart in ascending order for each level of X

Muhuri, Pradip (SAMHSA/CBHSQ) Pradip.Muhuri at samhsa.hhs.gov
Fri Jul 15 00:24:09 CEST 2011


Hello List,

The question is how to plot a bar chart in which bars are sorted  in ascending order for each level of X.  I would appreciate receiving your advice and help.


Thanks,

Pradip Muhuri

******

The following codes work when producing the chart in which bars are NOT sorted.  Please see the output.

***** Data File
5.1	8.7	1.6
3.7	7.4	2.8
10.4	12.0	3.5
4.4	8.8	1.7
2.0	3.5	0.7
6.7	11.0	3.1
5.3	6.7	1.8

###############
#source("C:/Documents and Settings/pradip.muhuri/My Documents/disorders_chart1.R") - Please ignore this line

#R Scripts for bar chart begin here

# Read drug data from tab-delimited data set
drug_data <- read.table("C:/Documents and Settings/pradip.muhuri/My Documents/xdrug.dat", header=FALSE,
                        col.names=c("Age_1217", "Age_1825", "Age_26Plus"),
			row.names = c("White","Black","Native American/Alaska Native","Hawaiian/OPI","Asian", "More than One Race", "Hispanic"),
			sep="\t")

# Graph drug use disorder data with adjacent bars using rainbow colors
barplot(as.matrix(drug_data), main="Past-Year Illicit Drug Use Disorders by Race/Ethnicity", ylab= "Past-Year Use Disorder Rate (%)", beside=TRUE, col=rainbow(7))
legend("topright", c("White","Black","Native American/Alaska Native","Hawaiian/OPI","Asian", "More than One Race", "Hispanic"), cex=0.6, bty="n", fill=rainbow(7));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bar_Graph.pdf
Type: application/pdf
Size: 4864 bytes
Desc: Bar_Graph.pdf
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110714/19065068/attachment.pdf>


More information about the R-help mailing list