[R] Plotting a graph for every Level of a Factor
jim holtman
jholtman at gmail.com
Thu Jan 8 00:49:23 CET 2009
Is this what you want:
> x # input data
Year Species Stock TACC Catch
1 2001 ORH OR1 5000 4687
2 2002 ORH OR1 6000 3215
3 2003 ORH OR1 7000 6782
4 2004 ORH OR1 9000 10000
5 2005 ORH OR1 9000 12000
6 2001 ORH OR3 20000 7892
7 2002 ORH OR3 25000 27000
8 2003 ORH OR3 30000 32000
9 2004 ORH OR3 30000 29000
10 2005 ORH OR3 30000 30000
11 2001 ORH OR5 23000 10982
12 2002 ORH OR5 23000 24590
13 2003 ORH OR5 23000 24035
14 2004 ORH OR5 25000 29008
15 2005 ORH OR5 20000 21092
> # split for plotting
> x.sp <- split(x, list(x$Species, x$Stock))
> # plot the data
> for (i in x.sp){
+ mp <- barplot(i$TACC, names.arg=i$Year,
+ main=paste(i$Species[1], i$Stock[1]),
+ ylim=c(0,max(i$TACC, i$Catch)))
+ lines(mp, i$Catch, type='b', pch=19)
+ }
>
On Wed, Jan 7, 2009 at 6:10 PM, jimdare <jamesdare26 at gmail.com> wrote:
>
> Hello,
>
> Using the dataset below, is there a way to generate a bar/line plot for the
> TACC/Catch of every lvl of stock? i.e. OR1,OR3,OR5. The picture at the
> bottom of this post is an example of the bar/line plot for OR1 which was
> generated when OR1 was the only stock in the table. This was created, with
> help from Marc Schwartz, using:
>
>> mp <- barplot(fish$TACC, space = 0, names.arg = fish$Year,ylim=c(0,13000))
>> lines(mp, fish$Catch, type = "b", pch = 19)
>
> Is there a way to instruct R to plot this for one particular stock from the
> table below, and, if so, is there a way to automate it so it plots a figure
> for each individual stock.
>
> Data frame (fish)
>
> Year Species Stock TACC Catch
> 2001 ORH OR1 5000 4687
> 2002 ORH OR1 6000 3215
> 2003 ORH OR1 7000 6782
> 2004 ORH OR1 9000 10000
> 2005 ORH OR1 9000 12000
> 2001 ORH OR3 20000 7892
> 2002 ORH OR3 25000 27000
> 2003 ORH OR3 30000 32000
> 2004 ORH OR3 30000 29000
> 2005 ORH OR3 30000 30000
> 2001 ORH OR5 23000 10982
> 2002 ORH OR5 23000 24590
> 2003 ORH OR5 23000 24035
> 2004 ORH OR5 25000 29008
> 2005 ORH OR5 20000 21092
>
> http://www.nabble.com/file/p21340956/OR1.gif
> --
> View this message in context: http://www.nabble.com/Plotting-a-graph-for-every-Level-of-a-Factor-tp21340956p21340956.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list