[R] plotting 0,1 data

William Dunlap wdunlap at tibco.com
Thu Aug 2 01:11:38 CEST 2012


Perhaps y is a factor.  E.g.,
> plot(x=c(3,5), y=factor(c(0,1)))
> plot(x=c(3,5), y=factor(c("Pig","Goat")))
both treat y as as.numeric(y), which is c(1,2) in the first
and c(2,1) in the second.

When you import data into R, always look at it with str()
and various plots to convince yourself it is what you think
it is.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of R. Michael Weylandt
> Sent: Wednesday, August 01, 2012 3:42 PM
> To: Georgiana May
> Cc: R-help at r-project.org
> Subject: Re: [R] plotting 0,1 data
> 
> Can you give a reproducible example: it doesn't for me
> 
> x <- c(3, 5)
> y <- c(0, 1)
> plot(x, y)
> 
> What you might be getting confused with is
> 
> plot(y)
> 
> where the x axis is now at 1 and 2 -- this is because when only given
> a single vector to plot, R plots the values against their indices,
> which, as all indexes in R, start at 0.
> 
> For more on how to make a reproducible example, see this resource and
> the links therein:
> 
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-
> example
> 
> Best,
> Michael
> 
> On Wed, Aug 1, 2012 at 1:41 PM, Georgiana May <gmay at umn.edu> wrote:
> > Hello,
> > Anyone know why the command:
> >> plot(x,y) where y is a 0,1 result
> > sometimes plots the y values as 1,2 rather than 0,1?
> >
> > And how to prevent this?
> >
> > Thank you,
> > Georgiana May
> >
> >         [[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.
> 
> ______________________________________________
> 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