Hi, When I use the function plot() to plot a categorical variable with two levels versus a continuous variable, the two levels of the categorical variable are plotted at the values of 1.0 and 2.0. I would like them to be plotted at the values of 0.0 and 1.0. How can I do this? Example: x <- 1:10 y <- as.factor(rep(c("A","B"),c(5,5))) plot(x,y) Thanks in advance. version: platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 6.1 year 2002 month 11 day 01 language R -- ****************************************************************** | Michael Fugate Phone: (505) 667-0398 | | Los Alamos National Laboratory Fax: (505) 665-5220 | | Group: CCS-3, Mail Stop: B265 e-mail: fugate at lanl.gov | | Los Alamos, NM 87545 | ******************************************************************
>>>>> "Michael" == Michael Lynn Fugate <fugate at trinidad.c3.lanl.gov> writes:> Hi, When I use the function plot() to plot a categorical > variable with two levels versus a continuous variable, the > two levels of the categorical variable are plotted at the > values of 1.0 and 2.0. I would like them to be plotted at > the values of 0.0 and 1.0. How can I do this? This is not quite what you are asking for, but it might serve just as well:> x <- 1:10 > y <- as.factor(rep(c("A","B"),c(5,5))) > dotchart(x,groups=y)or> require(lattice) > df<-data.frame(x,y) > stripplot(y~x, data=df)or> require(lattice) > df<-data.frame(x,y) > dotplot(y~x, data=df)Mike
Michael Lynn Fugate wrote:> > Hi, > > When I use the function plot() to plot a categorical variable with two > levels versus a continuous variable, the two levels of the categorical > variable are plotted at the values of 1.0 and 2.0. I would like them to > be plotted at the values of 0.0 and 1.0. How can I do this? > > Example: > > x <- 1:10 > y <- as.factor(rep(c("A","B"),c(5,5))) > plot(x,y)plot(x, as.integer(y) - 1) Uwe Ligges> Thanks in advance. > > version: > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 1 > minor 6.1 > year 2002 > month 11 > day 01 > language R > > -- > > ****************************************************************** > | Michael Fugate Phone: (505) 667-0398 | > | Los Alamos National Laboratory Fax: (505) 665-5220 | > | Group: CCS-3, Mail Stop: B265 e-mail: fugate at lanl.gov | > | Los Alamos, NM 87545 | > ****************************************************************** > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Dear Michael, You could use plot(x, as.numeric(y) - 1). John At 01:10 PM 2/3/2003 -0700, Michael Lynn Fugate wrote:>Hi, > >When I use the function plot() to plot a categorical variable with two >levels versus a continuous variable, the two levels of the categorical >variable are plotted at the values of 1.0 and 2.0. I would like them to >be plotted at the values of 0.0 and 1.0. How can I do this? > >Example: > >x <- 1:10 >y <- as.factor(rep(c("A","B"),c(5,5))) >plot(x,y)____________________________ John Fox Department of Sociology McMaster University email: jfox at mcmaster.ca web: http://www.socsci.mcmaster.ca/jfox