[R] categorical variable in scatterplot (car)
John Fox
jfox at mcmaster.ca
Sun Apr 25 16:40:30 CEST 2010
Dear Peter and Anthony,
Thanks, Peter, for answering the question, but scatterplot() should work
even if z is not a factor, and does for me in the following example:
> library(car)
> Prestige$tp <- with(Prestige, ifelse(type == "prof", 1, 0))
> scatterplot(prestige ~ income | tp, data=Prestige)
So, Anthony, the usual advice about providing a reproducible example seems
applicable here.
Regards,
John
--------------------------------
John Fox
Senator William McMaster
Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
> Behalf Of Peter Ehlers
> Sent: April-24-10 11:57 PM
> To: Anthony Lopez
> Cc: R-help at r-project.org
> Subject: Re: [R] categorical variable in scatterplot (car)
>
> On 2010-04-24 21:30, Anthony Lopez wrote:
> > Hello R folks,
> >
> > I am encountering a problem with the following scatterplot function from
> the
> > car package:
> >
> >> scatterplot(y~x|z)
> >
> > where y and x are continuous (interval) random variables and z is a
> > categorical variable. When z is a categorical variable coded 1 or 2, I
> > (appropriately) get a scatterplot of y by x, coded by z. Similarly,
when z
> > is a categorical variable coded 1, 2, or 3, there is again, no problem.
> > However, when z is a categorical variable coded 0 or 1, the
scatterplot
> >
> >> scatterplot(y~x|z)
> >
> > is exactly identical to the one generated by
> >
> >> scatterplot(y~x)
> >
> > It is not possible that this is due to the fact that there is no
difference
> > between the categories. It is as if R doesn't "see" that I want it
coded
> by
> > z. But this only happens when one of the categories of z is coded "0"
> (i.e.
> > zero). Any ideas why this is so, or how I can fix this without recoding
my
> > variable?
>
> Make z a factor (which it really should be anyway).
>
> -Peter Ehlers
>
> >
> > Thank you!
> >
> > Anthony
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
> >
>
> --
> Peter Ehlers
> University of Calgary
>
> ______________________________________________
> 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.
More information about the R-help
mailing list