Re: [R] Barplot by two variables

2007-05-15 Thread Spilak,Jacqueline [Edm]

 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:[EMAIL PROTECTED] 
Sent: May 10, 2007 4:58 PM
To: Spilak,Jacqueline [Edm]
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Barplot by two variables

On 5/10/07, Spilak,Jacqueline [Edm] [EMAIL PROTECTED] 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).
 YearLimit   HSS
 1999ALT 0.675
 1999VFR 0.521
 2000ALT 0.264
 2000VFR 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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Barplot by two variables

2007-05-10 Thread Spilak,Jacqueline [Edm]
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).
YearLimit   HSS
1999ALT 0.675
1999VFR 0.521   
2000ALT 0.264
2000VFR 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.  

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Barplot by two variables

2007-05-10 Thread Deepayan Sarkar
On 5/10/07, Spilak,Jacqueline [Edm] [EMAIL PROTECTED] 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).
 YearLimit   HSS
 1999ALT 0.675
 1999VFR 0.521
 2000ALT 0.264
 2000VFR 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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Barplot by two variables

2007-05-10 Thread Marc Schwartz
On Thu, 2007-05-10 at 15:58 -0700, Deepayan Sarkar wrote:
 On 5/10/07, Spilak,Jacqueline [Edm] [EMAIL PROTECTED] 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).
  YearLimit   HSS
  1999ALT 0.675
  1999VFR 0.521
  2000ALT 0.264
  2000VFR 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)

And here is one using barplot():

 DF
  Year Limit   HSS
1 1999   ALT 0.675
2 1999   VFR 0.521
3 2000   ALT 0.264
4 2000   VFR 0.295


barplot(matrix(DF$HSS, ncol = 2), beside = TRUE, 
names.arg = unique(DF$Year), 
legend.text = unique(DF$Limit)


Note that I convert DF$HSS to a two column matrix to enable using the
built-in 'beside' argument in barplot() for the bar pairings, much like
Deepayan has used the formula in barchart() above.

Then it is a matter of getting the unique values for both the Years and
the Limits to use them for the x axis labels and the legend text.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.