[R] Subset for plot in R
Greg Snow
538280 at gmail.com
Wed Feb 19 18:26:17 CET 2014
So are the names of the columns in the dataset x, y, and z? or are
they area, concentration, and year? you seem to be mixing these
together? If you provide a minimal reproducible example (provide some
data with dput, or the commands to generate random data, or use a
built in dataset) then it makes it easier for us to help you.
Is the z/year variable a set of character strings? a factor? or a
numeric/integer variable?
Assuming the column names are x, y, and z and that z is the numeric
year and data is a data frame, then here are some options that should
work:
plot( data$x[ data$z >= 2012 ], data$y[ data$z >= 2012 )
with( data[ data$z >= 2012, ], plot(x,y) )
plot( y~x, data=data, subset= z >= 2012 )
Also see `fortune("dog")` about choosing names for data frames.
On Mon, Feb 17, 2014 at 9:18 AM, arun <smartpink111 at yahoo.com> wrote:
> Hi,
> Try:
> set.seed(49)
> dat1 <- data.frame(year= rep(2010:2013,c(10,8,9,13)),x=sample(1e4,40,replace=TRUE),y=sample(40,40,replace=TRUE))
> plot(x~y,data=dat1,subset=year > 2012)
> #or
> with(subset(dat1,year > 2012),plot(y,x))
>
>
> A.K.
>
>
>
> Hi R people
>
> This might take me the whole day to figure out, instead I will ask so I can save some PhD time.
>
> I want to plot a subset of my data.
>
> x = area
> y = concentration
>
> these data are sorted by
>
> z = year (2008 to 2013)
>
> So I want to make a plot where I can see x and y >=2012 and <2012.
>
> I have tied
> plot(data$y[year>='2012'], x[year>='2012']) That did not work.
>
> also plot(data$y, data$x, year>'2012') did not give the right data plot
>
> Any suggestions on how to do this would be appreciated.
> thanks
>
> ______________________________________________
> 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.
--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com
More information about the R-help
mailing list