Daniel Kornhauser
2009-Jan-30 03:53 UTC
[Rd] How to generate a xyplot with multiple panels using an empty data frame ?
Hi: I am coding some interactive interface using an xyplot from lattice. When a user clicks on a panel of the xyplot, a simulation is executed and the resulting data is plotted on the corresponding panel. The problem is that I start with an empty data frame and only fill it as the user request data from simulations. And, I have found it impossible to create a conditional plot that contains panels using an empty data frame. For example I want: library(lattice) e = data.frame("a", "b", "c", "d") xyplot(X.a. ~ X.b. | X.c. + X.d., data = e, xlim = c(c(50,60),c(60,70)), ylim = c(c(10,20),c(20,30)), drop.unused.levels=FALSE,layout = c(2,2)) to create a empty xyplot that would look like: 50 60 70 ---------------------------- 10 | | | | | | | | | 20 ---------------------------- | | | | | | 30 | | | ----------------------------- but it doesn't create 4 panels it only creates a single panel: 50 60 70 --------------- 10 | | 20 | | 30 | | ---------------- I am a novice in R so I hope this is not a question that is too easy for the r-devel list. Thanks. Daniel. PS: I got around this problem by creating "dummy" data frames containing data with the sole purpose of indicating xyplot the data rages. It works well, but I consider it a hack. [[alternative HTML version deleted]]
Peter Cowan
2009-Jan-30 04:04 UTC
[Rd] How to generate a xyplot with multiple panels using an empty data frame ?
On Thu, Jan 29, 2009 at 7:53 PM, Daniel Kornhauser <dkor at northwestern.edu> wrote:> Hi: > > I am coding some interactive interface using an xyplot from lattice. > When a user clicks on a panel of the xyplot, a simulation is executed and > the resulting data is plotted on the corresponding panel. > The problem is that I start with an empty data frame and only fill it as the > user request data from simulations. > And, I have found it impossible to create a conditional plot that contains > panels using an empty data frame. > > For example I want: > > library(lattice) > e = data.frame("a", "b", "c", "d") > xyplot(X.a. ~ X.b. | X.c. + X.d., data = e, xlim = c(c(50,60),c(60,70)), > ylim = c(c(10,20),c(20,30)), drop.unused.levels=FALSE,layout = c(2,2)) > > to create a empty xyplot that would look like: > > 50 60 70 > ---------------------------- > 10 | | | > | | | > | | | > 20 ---------------------------- > | | | > | | | > 30 | | | > ----------------------------- > > but it doesn't create 4 panels it only creates a single panel: > > 50 60 70 > --------------- > 10 | | > 20 | | > 30 | | > ---------------- > > I am a novice in R so I hope this is not a question that is too easy for the > r-devel list.I think you've directed your email to the wrong list. R-devel, is primarily targeted at people who write add-on packages (such as lattice itself) or the R core. Please see: <http://www.r-project.org/posting-guide.html#which_list> This question should be directed to r-help which you can subscribe to here: <http://www.r-project.org/mail.html>> > Thanks. > > Daniel. > > PS: I got around this problem by creating "dummy" data frames containing > data with the sole purpose of indicating xyplot the data rages. > It works well, but I consider it a hack.If it that works, why do you consider it a hack? There's probably a more elegant way, but I would probably just make data frames, filled with NA. HTH Peter