[R] categorical variable in scatterplot (car)

Peter Ehlers ehlers at ucalgary.ca
Sun Apr 25 05:57:21 CEST 2010


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



More information about the R-help mailing list