Not the most straightforward way, but I think it gets the job done:
x <- read.table(textConnection("Ageclass Scale Mean Sex
1 21-40 BP 40.26667 female
2 41-60 BP 34.10714 female
3 61-79 BP 37.30000 female
4 21-40 GH 30.25000 female
5 41-60 GH 39.00926 female
6 61-79 GH 49.30000 female
7 21-40 MH 56.53333 female
8 41-60 MH 62.42857 female
9 61-79 MH 72.72727 female
10 21-40 PF 25.86111 female
11 41-60 PF 42.42063 female
12 61-79 PF 52.17172 female
13 21-40 RE 38.09524 female
14 41-60 RE 42.85714 female
15 61-79 RE 42.42424 female
16 21-40 RP 20.00000 female
17 41-60 RP 25.89286 female
18 61-79 RP 15.90909 female
19 21-40 SF 51.66667 female
20 41-60 SF 63.88889 female
21 61-79 SF 57.95455 female
22 21-40 VT 32.11111 female
23 41-60 VT 36.96429 female
24 61-79 VT 33.18182 female
25 21-40 BP 35.00000 male
26 41-60 BP 37.75000 male
27 61-79 BP 36.00000 male
28 21-40 GH 42.16667 male
29 41-60 GH 41.89062 male
30 61-79 GH 41.40000 male
31 21-40 MH 72.00000 male
32 41-60 MH 66.60417 male
33 61-79 MH 75.20000 male
34 21-40 PF 41.85185 male
35 41-60 PF 55.31250 male
36 61-79 PF 47.00000 male
37 21-40 RE 37.03704 male
38 41-60 RE 54.16667 male
39 61-79 RE 46.66667 male
40 21-40 RP 27.77778 male
41 41-60 RP 28.12500 male
42 61-79 RP 20.00000 male
43 21-40 SF 61.11111 male
44 41-60 SF 66.40625 male
45 61-79 SF 60.00000 male
46 21-40 VT 38.88889 male
47 41-60 VT 30.93750 male
48 61-79 VT 42.00000 male"), header=TRUE)
# setup the plot for the max range
plot(0, type='n', ylim=range(x$Mean), xlim=range(as.integer(x$Scale)),
xaxt='n',
ylab="Mean", xlab="Scale")
# plot the axis
axis(1, at=seq_along(levels(x$Scale)), labels=levels(x$Scale))
# split the data
x.s <- split(x, list(x$Ageclass, x$Sex))
# plot the data
invisible(lapply(seq_along(x.s), function(.grp){
lines(as.integer(x.s[[.grp]]$Scale), x.s[[.grp]]$Mean, col=.grp,
type='o')
}))
legend('topleft', legend=names(x.s), lwd=3, col=seq_along(x.s))
On Feb 12, 2008 12:21 PM, Tom Cohen <tom.cohen78@yahoo.se> wrote:
> Dear list,
>
> I have following data set, which I want to plot the "Scale"
variable on
> the
> x-axis and "Mean"´on the y-axis for each Ageclass and for each
sex. The
> Mean
> value of each Ageclass for each sex would be connected by a line.
> Totally,
> there should be 6 lines, from which three present the Mean values of each
> Ageclass for respective sex. Are there any easy ways to do this in R?
>
>
> Ageclass Scale Mean Sex
> 1 21-40 BP 40.26667 female
> 2 41-60 BP 34.10714 female
> 3 61-79 BP 37.30000 female
> 4 21-40 GH 30.25000 female
> 5 41-60 GH 39.00926 female
> 6 61-79 GH 49.30000 female
> 7 21-40 MH 56.53333 female
> 8 41-60 MH 62.42857 female
> 9 61-79 MH 72.72727 female
> 10 21-40 PF 25.86111 female
> 11 41-60 PF 42.42063 female
> 12 61-79 PF 52.17172 female
> 13 21-40 RE 38.09524 female
> 14 41-60 RE 42.85714 female
> 15 61-79 RE 42.42424 female
> 16 21-40 RP 20.00000 female
> 17 41-60 RP 25.89286 female
> 18 61-79 RP 15.90909 female
> 19 21-40 SF 51.66667 female
> 20 41-60 SF 63.88889 female
> 21 61-79 SF 57.95455 female
> 22 21-40 VT 32.11111 female
> 23 41-60 VT 36.96429 female
> 24 61-79 VT 33.18182 female
> 25 21-40 BP 35.00000 male
> 26 41-60 BP 37.75000 male
> 27 61-79 BP 36.00000 male
> 28 21-40 GH 42.16667 male
> 29 41-60 GH 41.89062 male
> 30 61-79 GH 41.40000 male
> 31 21-40 MH 72.00000 male
> 32 41-60 MH 66.60417 male
> 33 61-79 MH 75.20000 male
> 34 21-40 PF 41.85185 male
> 35 41-60 PF 55.31250 male
> 36 61-79 PF 47.00000 male
> 37 21-40 RE 37.03704 male
> 38 41-60 RE 54.16667 male
> 39 61-79 RE 46.66667 male
> 40 21-40 RP 27.77778 male
> 41 41-60 RP 28.12500 male
> 42 61-79 RP 20.00000 male
> 43 21-40 SF 61.11111 male
> 44 41-60 SF 66.40625 male
> 45 61-79 SF 60.00000 male
> 46 21-40 VT 38.88889 male
> 47 41-60 VT 30.93750 male
> 48 61-79 VT 42.00000 male
> Thanks for any help,
> Tom
>
>
> ---------------------------------
> Går det långsamt? Skaffa dig en snabbare bredbandsuppkoppling.
>
> [[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<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 you are trying to solve?
[[alternative HTML version deleted]]