Hello, I am trying to plot age distribution data for a certain condition that runs in families. Below is a simplified view of the dataset, i.e. in this case there are four families, each line corresponding to one individual with age at diagnosis and sex.> famdatafamily age sex 1 fam1 2.1 f 2 fam1 2.3 f 3 fam1 1.0 m 4 fam2 7.3 f 5 fam2 4.1 f 6 fam2 1.2 f 7 fam2 0.6 m 8 fam3 3.5 m 9 fam3 2.5 m 10 fam3 2.9 m 11 fam3 5.6 m 12 fam3 4.4 f 13 fam10 1.1 f 14 fam10 1.2 f 15 fam10 2.9 f 16 fam10 2.2 f 17 fam10 4.7 m I can nicely plot the age distribution by families with> stripchart(famdata$age~famdata$family)I would like to plot datapoints according to the sex of the person, e.g. circle for a girl and square for a boy, like this:> stripchart(famdata$age~famdata$family, pch=ifelse(famdata$sex=="m",22, 1)) But this command doesn't work as I expected. Datapoints from fam2 are shown as squares, all the rest as circles. Still , this seems OK:> ifelse(famdata$sex=="m", 22, 1)[1] 1 1 22 1 1 1 22 22 22 22 22 1 1 1 1 1 22 Any clues ? Thanks a lot for your help, alex
> Hello, > > I am trying to plot age distribution data for a certain condition that > runs in families. Below is a simplified view of the dataset, i.e. in > this case there are four families, each line corresponding to one > individual with age at diagnosis and sex. > > > famdata > family age sex > 1 fam1 2.1 f > 2 fam1 2.3 f > 3 fam1 1.0 m > 4 fam2 7.3 f > 5 fam2 4.1 f > 6 fam2 1.2 f > 7 fam2 0.6 m > 8 fam3 3.5 m > 9 fam3 2.5 m > 10 fam3 2.9 m > 11 fam3 5.6 m > 12 fam3 4.4 f > 13 fam10 1.1 f > 14 fam10 1.2 f > 15 fam10 2.9 f > 16 fam10 2.2 f > 17 fam10 4.7 m > > I can nicely plot the age distribution by families with > > > stripchart(famdata$age~famdata$family) > > I would like to plot datapoints according to the sex of the person, e.g. > circle for a girl and square for a boy, like this: > > > stripchart(famdata$age~famdata$family, pch=ifelse(famdata$sex=="m", > 22, 1))Try this: stripchart(famdata$age ~ famdata$family, pch = c(1, 22)[unclass(famdata$sex)]) (maybe you need to have "c(22, 1)") HTH Emmanuel Paradis> > But this command doesn't work as I expected. Datapoints from fam2 are > shown as squares, all the rest as circles. Still , this seems OK: > > > ifelse(famdata$sex=="m", 22, 1) > [1] 1 1 22 1 1 1 22 22 22 22 22 1 1 1 1 1 22 > > Any clues ? > > Thanks a lot for your help, > > alex > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
stripchart always plots all the points in a given group with the same symbol, so you can't do what you want with it. Here are some alternatives: 1. Its not very nice but coplot can get you a chart somewhat in the vein you are looking for: with(famdata, coplot(age~family|family, pch=ifelse(sex=="m",22,1))) 2. With a bit more work, you can try creating it yourself using plot: with(famdata, plot(age, as.numeric(family), pch=ifelse(sex=="m",22,1),axes=F)) axis(1) lv <- levels(famdata$family) axis(2,seq(lv),lv) I have not examined the above closely so you might want to double check them. --- Hello, I am trying to plot age distribution data for a certain condition that runs in families. Below is a simplified view of the dataset, i.e. in this case there are four families, each line corresponding to one individual with age at diagnosis and sex.> famdatafamily age sex 1 fam1 2.1 f 2 fam1 2.3 f 3 fam1 1.0 m 4 fam2 7.3 f 5 fam2 4.1 f 6 fam2 1.2 f 7 fam2 0.6 m 8 fam3 3.5 m 9 fam3 2.5 m 10 fam3 2.9 m 11 fam3 5.6 m 12 fam3 4.4 f 13 fam10 1.1 f 14 fam10 1.2 f 15 fam10 2.9 f 16 fam10 2.2 f 17 fam10 4.7 m I can nicely plot the age distribution by families with> stripchart(famdata$age~famdata$family)I would like to plot datapoints according to the sex of the person, e.g. circle for a girl and square for a boy, like this:> stripchart(famdata$age~famdata$family, pch=ifelse(famdata$sex=="m",22, 1)) But this command doesn't work as I expected. Datapoints from fam2 are shown as squares, all the rest as circles. Still , this seems OK:> ifelse(famdata$sex=="m", 22, 1)[1] 1 1 22 1 1 1 22 22 22 22 22 1 1 1 1 1 22 Any clues ? Thanks a lot for your help, alex
>I would like to plot datapoints according to the sex of the person, e.g. >circle for a girl and square for a boy, like this: > > >Have you tried using stripplot (a lattice plot) instead? You can then use the group argument to display different groups differently. eg. stripplot(age ~ family, data=famdata, group=sex) Hadley