[R] Grouped Barplot
Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Sample data is attached -- there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly appreciated! ~Gary __ R-help@r-project.org 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] Grouped Barplot
On 11/25/2009 07:48 PM, Gary wrote: Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Sample data is attached -- there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly appreciated! ~Gary __ R-help@r-project.org 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. Have a look at https://stat.ethz.ch/pipermail/r-help/2000-November/009191.html. Might be what you're looking for. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Grouped Barplot
On Nov 25, 2009, at 1:48 PM, Gary wrote: Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Looks like a product of a function from ggplot2. In fact trimming that URL brings you to a page with the code that created it! Sample data is attached -- No, it's not. Read the Posting Guide for what file types are acceptable to the server. I suspect you will get better success if the extension is .txt, even if it is comma separated. Or better yet follow the directions there for posting data in a form that can be enclosed in your posting and copy-pasted into the console session. there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly appreciated! David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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] Grouped Barplot
Thanks David. I reduced the data set and its copied below (also attached to this email as text file). Now N=50, Only 2 years, Only 2 Cities. I tried: foo-read.table(SampleData.txt, header=TRUE) boxplot(foo$admit ~ foo$city + foo$year, col=2:3) I need some help with: 1) Defining labels for x-axis (just 2000 and 2001). 2) Removing gap between cities boxplots (but leaving gap between years). 3) Adding MEAN to the boxplots. 4) Adding legend including color + city name. city year admit Asheville2000 0 Asheville2000 0 Asheville2000 1 Asheville2000 2 Asheville2000 2 Asheville2000 0 Asheville2000 1 Asheville2000 0 Asheville2000 0 Asheville2000 0 Asheville2000 2 Asheville2000 3 Asheville2000 1 Asheville2000 2 Asheville2000 1 Asheville2000 1 Asheville2000 0 Asheville2000 0 Asheville2000 1 Asheville2001 1 Asheville2001 3 Asheville2001 0 Asheville2001 0 Asheville2001 2 Asheville2001 3 Asheville2001 3 Charlotte2000 5 Charlotte2000 1 Charlotte2000 0 Charlotte2000 4 Charlotte2000 1 Charlotte2000 3 Charlotte2000 0 Charlotte2000 3 Charlotte2000 3 Charlotte2000 3 Charlotte2000 2 Charlotte2000 1 Charlotte2000 1 Charlotte2000 3 Charlotte2001 1 Charlotte2001 4 Charlotte2001 2 Charlotte2001 4 Charlotte2001 3 Charlotte2001 3 Charlotte2001 1 Charlotte2001 7 Charlotte2001 4 Charlotte2001 1 Sample: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Thanks! On Wed, Nov 25, 2009 at 2:45 PM, David Winsemius dwinsem...@comcast.netwrote: On Nov 25, 2009, at 1:48 PM, Gary wrote: Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Looks like a product of a function from ggplot2. In fact trimming that URL brings you to a page with the code that created it! Sample data is attached -- No, it's not. Read the Posting Guide for what file types are acceptable to the server. I suspect you will get better success if the extension is .txt, even if it is comma separated. Or better yet follow the directions there for posting data in a form that can be enclosed in your posting and copy-pasted into the console session. there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly appreciated! David Winsemius, MD Heritage Laboratories West Hartford, CT city year admit Asheville2000 0 Asheville2000 0 Asheville2000 1 Asheville2000 2 Asheville2000 2 Asheville2000 0 Asheville2000 1 Asheville2000 0 Asheville2000 0 Asheville2000 0 Asheville2000 2 Asheville2000 3 Asheville2000 1 Asheville2000 2 Asheville2000 1 Asheville2000 1 Asheville2000 0 Asheville
Re: [R] Grouped Barplot
I'm able to add legend. ~Gary On Wed, Nov 25, 2009 at 3:15 PM, Gary mail2garymil...@gmail.com wrote: Thanks David. I reduced the data set and its copied below (also attached to this email as text file). Now N=50, Only 2 years, Only 2 Cities. I tried: foo-read.table(SampleData.txt, header=TRUE) boxplot(foo$admit ~ foo$city + foo$year, col=2:3) I need some help with: 1) Defining labels for x-axis (just 2000 and 2001). 2) Removing gap between cities boxplots (but leaving gap between years). 3) Adding MEAN to the boxplots. city year admit Asheville2000 0 Asheville2000 0 Asheville2000 1 Asheville2000 2 Asheville2000 2 Asheville2000 0 Asheville2000 1 Asheville2000 0 Asheville2000 0 Asheville2000 0 Asheville2000 2 Asheville2000 3 Asheville2000 1 Asheville2000 2 Asheville2000 1 Asheville2000 1 Asheville2000 0 Asheville2000 0 Asheville2000 1 Asheville2001 1 Asheville2001 3 Asheville2001 0 Asheville2001 0 Asheville2001 2 Asheville2001 3 Asheville2001 3 Charlotte2000 5 Charlotte2000 1 Charlotte2000 0 Charlotte2000 4 Charlotte2000 1 Charlotte2000 3 Charlotte2000 0 Charlotte2000 3 Charlotte2000 3 Charlotte2000 3 Charlotte2000 2 Charlotte2000 1 Charlotte2000 1 Charlotte2000 3 Charlotte2001 1 Charlotte2001 4 Charlotte2001 2 Charlotte2001 4 Charlotte2001 3 Charlotte2001 3 Charlotte2001 1 Charlotte2001 7 Charlotte2001 4 Charlotte2001 1 Sample: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Thanks! On Wed, Nov 25, 2009 at 2:45 PM, David Winsemius dwinsem...@comcast.netwrote: On Nov 25, 2009, at 1:48 PM, Gary wrote: Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Looks like a product of a function from ggplot2. In fact trimming that URL brings you to a page with the code that created it! Sample data is attached -- No, it's not. Read the Posting Guide for what file types are acceptable to the server. I suspect you will get better success if the extension is .txt, even if it is comma separated. Or better yet follow the directions there for posting data in a form that can be enclosed in your posting and copy-pasted into the console session. there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly appreciated! David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org 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.