[R] Barplot by two variables
Spilak,Jacqueline [Edm]
Jacqueline.Spilak at EC.gc.ca
Tue May 15 23:22:58 CEST 2007
Thanks for your solution, it worked perfectly, it was exactly what I
wanted. I do have two more questions and hope you can help. I have
another analysis exactly like the last one except it is done by month
instead of year. When I graph it using barchart it makes the months go
in alphabetical order. Is there anyway to change it so that the months
go in the correct order (jan, feb, march, etc,). And how do I change
the colors of the bars in the graph, they are weird colors and I want to
change them.
Thanks so much for your help.
-----Original Message-----
From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com]
Sent: May 10, 2007 4:58 PM
To: Spilak,Jacqueline [Edm]
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Barplot by two variables
On 5/10/07, Spilak,Jacqueline [Edm] <Jacqueline.Spilak at ec.gc.ca> wrote:
> Hi all
> I have a bit of a problem. I want to make a barplot of some data. My
> data is of a score that is separated by year and by a limit (above 3
> and below 3 to calculate the score).
> Year Limit HSS
> 1999 ALT 0.675
> 1999 VFR 0.521
> 2000 ALT 0.264
> 2000 VFR 0.295
>
> I would like to have a barplot with year on the x axis and HSS on the
> y axis and the two limits as two different colors to show the
difference.
> Using (dataset$HSS, col=c("green","purple")) I get some of the plot
> but I don't know how to get labels on the bottom for each year and I
> can't get a legend for my barplot. Not really sure what I am doing
> wrong but any help would be much appreciated.
Here's one solution using the lattice package:
library(lattice)
barchart(HSS ~ factor(Year), data = dataset, origin = 0,
groups = Limit, auto.key = TRUE)
-Deepayan
More information about the R-help
mailing list