Søren Højsgaard
2006-Nov-01 17:05 UTC
[R] xyplot: Plotting two variables, one as points - the other as line. Can that be done without explicitly using panel functions
Hi! Consider d <- data.frame(x=1:10,y=5+1:10, yf=rnorm(10,5+1:10)) x y yf 1 1 6 5.268621 2 2 7 8.623896 3 3 8 8.114830 4 4 9 10.125955 5 5 10 9.977261 ... I plot y and yf against x with xyplot(y+yf~x,data=d,col=c('red','green'),pch=c("a","b")) BUT - I would like that the plot of y against x is with type='l' and the plot of yf against x is with type='p'. 1) Can this be done easily (i.e. without panel functions)? (Doing xyplot(y+yf~x,data=d,type=c("l","p"),col=c('red','green'),pch=c("a","b")) is not the way ahead) 2) How to do it with panel functions? Thanks in advance S?ren
Deepayan Sarkar
2006-Nov-01 17:41 UTC
[R] xyplot: Plotting two variables, one as points - the other as line. Can that be done without explicitly using panel functions
On 11/1/06, S?ren H?jsgaard <Soren.Hojsgaard at agrsci.dk> wrote:> Hi! Consider > d <- data.frame(x=1:10,y=5+1:10, yf=rnorm(10,5+1:10)) > x y yf > 1 1 6 5.268621 > 2 2 7 8.623896 > 3 3 8 8.114830 > 4 4 9 10.125955 > 5 5 10 9.977261 > ... > > I plot y and yf against x with > > xyplot(y+yf~x,data=d,col=c('red','green'),pch=c("a","b")) > > BUT - I would like that the plot of y against x is with type='l' and the plot of yf against x is with type='p'. > > 1) Can this be done easily (i.e. without panel functions)? (Doing > > xyplot(y+yf~x,data=d,type=c("l","p"),col=c('red','green'),pch=c("a","b")) > > is not the way ahead)xyplot(y+yf~x,data=d,type=c("l","p"),col=c('red','green'), pch=c("a","b"), distribute.type = TRUE)> 2) How to do it with panel functions?See ?panel.superpose -Deepayan
Gabor Grothendieck
2006-Nov-01 17:45 UTC
[R] xyplot: Plotting two variables, one as points - the other as line. Can that be done without explicitly using panel functions
If the x values are unique, as in this example, then xyplot.zoo can do it without a panel function (or perhaps more accurately the default panel function in xyplot.zoo can do it). Note that a zoo object is a vector or matrix with a time index attached to it. You don't really have to be familiar with zoo manipulations for this but there is zoo vignette if you want. library(lattice) libary(zoo) set.seed(1) d <- data.frame(x=1:10,y=5+1:10, yf=rnorm(10,5+1:10)) z <- with(d, zoo(cbind(y, yf), x)) # create zoo object, x is time xyplot(z, col = 2:3, type = c("l", "p"), pch = "b", screen = 1) On 11/1/06, S?ren H?jsgaard <Soren.Hojsgaard at agrsci.dk> wrote:> Hi! Consider > d <- data.frame(x=1:10,y=5+1:10, yf=rnorm(10,5+1:10)) > x y yf > 1 1 6 5.268621 > 2 2 7 8.623896 > 3 3 8 8.114830 > 4 4 9 10.125955 > 5 5 10 9.977261 > ... > > I plot y and yf against x with > > xyplot(y+yf~x,data=d,col=c('red','green'),pch=c("a","b")) > > BUT - I would like that the plot of y against x is with type='l' and the plot of yf against x is with type='p'. > > 1) Can this be done easily (i.e. without panel functions)? (Doing > > xyplot(y+yf~x,data=d,type=c("l","p"),col=c('red','green'),pch=c("a","b")) > > is not the way ahead) > > 2) How to do it with panel functions? > > Thanks in advance > S?ren > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Reasonably Related Threads
- lattice/xyplot: plotting 4 variables in two panels - can this be done?
- xyplot: getting data into the panel function
- Fwd: How to sample from a linear mixed model
- Calling substitute(expr, list(a=1)) when expr <- expression(a+b+c)
- Drawing a graph with vertices and edges using tcl/tk