Dear r-help, I draw graphics with xyplot and want to add some text to each panel (actually, the slope, error and significance of a regression line). I have defined the function, drawing a single panel and pass it to xyplot in the panel argument. This function calls panel.xyplot, calculates linear regression and formats coefficients. Now I want the text, I mentioned above, to be put in the upper left corner of each plot. I use ltext, and I need to define coordinates x and y. In order to do this I need to know the limits of x and y axes. I do not want to pass arguments xlim and ylim to the xyplot function and want it to calculate them automatically. And I also want to know the result of calculations. :) How to do this? Thank you very much. -- Best regards Wladimir Eremeev mailto:wl at eimb.ru ========================================================================== Research Scientist, PhD Leninsky Prospect 33, Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071, Institute of Ecology, Phone: (095) 135-9972; Russian Academy of Sciences Fax: (095) 135-9972
Lattice: how to get default ylim?
7 messages · Vladimir Eremeev, David James, Deepayan Sarkar +1 more
Hi,
Within your panel function you can use current.viewport() to recover
the active grid viewport and get xlim/ylim (in addition to other very
useful information). Then you can use grid.text (plus any other
grid.* function), e.g.,
require(grid)
my.panel <-
function(...)
{
panel.xyplot(...)
## add "Hello World on the top-left of each panel
v <- current.viewport() ## requires R 2.1.0 (I believe)
xlim <- v$xscale
ylim <- v$yscale
grid.text(x = xlim[1], y = ylim[2], default.units="native",
label = "Hello World", just= c("left", "top"))
}
Hope this helps.
--
David
Wladimir Eremeev wrote:
Dear r-help, I draw graphics with xyplot and want to add some text to each panel (actually, the slope, error and significance of a regression line). I have defined the function, drawing a single panel and pass it to xyplot in the panel argument. This function calls panel.xyplot, calculates linear regression and formats coefficients. Now I want the text, I mentioned above, to be put in the upper left corner of each plot. I use ltext, and I need to define coordinates x and y. In order to do this I need to know the limits of x and y axes. I do not want to pass arguments xlim and ylim to the xyplot function and want it to calculate them automatically. And I also want to know the result of calculations. :) How to do this? Thank you very much. -- Best regards Wladimir Eremeev mailto:wl at eimb.ru ========================================================================== Research Scientist, PhD Leninsky Prospect 33, Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071, Institute of Ecology, Phone: (095) 135-9972; Russian Academy of Sciences Fax: (095) 135-9972
______________________________________________ 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
Deepayan Sarkar wrote:
On Thursday 19 May 2005 8:00 am, David James wrote:
Hi,
Within your panel function you can use current.viewport() to recover
the active grid viewport and get xlim/ylim (in addition to other very
useful information). Then you can use grid.text (plus any other
grid.* function), e.g.,
require(grid)
my.panel <-
function(...)
{
panel.xyplot(...)
## add "Hello World on the top-left of each panel
v <- current.viewport() ## requires R 2.1.0 (I believe)
No, I think it's been there for a while. However, AFAIR the fact that viewports have components xscale and yscale that can be accessed like this is undocumented and may change if the implementation changes (which is a real possibility). Ideally, there should be exported interfaces to access this information, either in grid or lattice. One of the reasons there isn't is that you rarely
Yes, I agree that such an interface is quite desirable.
need it, including in this example (see below).
xlim <- v$xscale
ylim <- v$yscale
grid.text(x = xlim[1], y = ylim[2], default.units="native",
label = "Hello World", just= c("left", "top"))
An equivalent version where you don't need xlim and ylim is
grid.text(x = 0, y = 1, default.units="npc",
label = "Hello World", just= c("left", "top"))
Right, in this silly "Hello World" example you don't need xlim/ylim, but one can see instances where one would...
Deepayan
} Hope this helps. -- David Wladimir Eremeev wrote:
Dear r-help, I draw graphics with xyplot and want to add some text to each panel (actually, the slope, error and significance of a regression line). I have defined the function, drawing a single panel and pass it to xyplot in the panel argument. This function calls panel.xyplot, calculates linear regression and formats coefficients. Now I want the text, I mentioned above, to be put in the upper left corner of each plot. I use ltext, and I need to define coordinates x and y. In order to do this I need to know the limits of x and y axes. I do not want to pass arguments xlim and ylim to the xyplot function and want it to calculate them automatically. And I also want to know the result of calculations. :) How to do this? Thank you very much. -- Best regards Wladimir Eremeev mailto:wl at eimb.ru ========================================================================= = Research Scientist, PhD Leninsky Prospect 33, Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071, Institute of Ecology, Phone: (095) 135-9972; Russian Academy of Sciences Fax: (095) 135-9972
______________________________________________ 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
______________________________________________ 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
On Thursday 19 May 2005 8:00 am, David James wrote:
Hi,
Within your panel function you can use current.viewport() to recover
the active grid viewport and get xlim/ylim (in addition to other very
useful information). Then you can use grid.text (plus any other
grid.* function), e.g.,
require(grid)
my.panel <-
function(...)
{
panel.xyplot(...)
## add "Hello World on the top-left of each panel
v <- current.viewport() ## requires R 2.1.0 (I believe)
No, I think it's been there for a while. However, AFAIR the fact that viewports have components xscale and yscale that can be accessed like this is undocumented and may change if the implementation changes (which is a real possibility). Ideally, there should be exported interfaces to access this information, either in grid or lattice. One of the reasons there isn't is that you rarely need it, including in this example (see below).
xlim <- v$xscale
ylim <- v$yscale
grid.text(x = xlim[1], y = ylim[2], default.units="native",
label = "Hello World", just= c("left", "top"))
An equivalent version where you don't need xlim and ylim is
grid.text(x = 0, y = 1, default.units="npc",
label = "Hello World", just= c("left", "top"))
Deepayan
} Hope this helps. -- David Wladimir Eremeev wrote:
Dear r-help, I draw graphics with xyplot and want to add some text to each panel (actually, the slope, error and significance of a regression line). I have defined the function, drawing a single panel and pass it to xyplot in the panel argument. This function calls panel.xyplot, calculates linear regression and formats coefficients. Now I want the text, I mentioned above, to be put in the upper left corner of each plot. I use ltext, and I need to define coordinates x and y. In order to do this I need to know the limits of x and y axes. I do not want to pass arguments xlim and ylim to the xyplot function and want it to calculate them automatically. And I also want to know the result of calculations. :) How to do this? Thank you very much. -- Best regards Wladimir Eremeev mailto:wl at eimb.ru ========================================================================= = Research Scientist, PhD Leninsky Prospect 33, Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071, Institute of Ecology, Phone: (095) 135-9972; Russian Academy of Sciences Fax: (095) 135-9972
______________________________________________ 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
______________________________________________ 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
On Thursday 19 May 2005 9:11 am, David James wrote:
Deepayan Sarkar wrote:
v <- current.viewport() ## requires R 2.1.0 (I believe)
No, I think it's been there for a while. However, AFAIR the fact that viewports have components xscale and yscale that can be accessed like this is undocumented and may change if the implementation changes (which is a real possibility). Ideally, there should be exported interfaces to access this information, either in grid or lattice. One of the reasons there isn't is that you rarely
Yes, I agree that such an interface is quite desirable.
OK, I'll put something in the next version of lattice. Deepayan
Hi
Deepayan Sarkar wrote:
On Thursday 19 May 2005 9:11 am, David James wrote:
Deepayan Sarkar wrote:
v <- current.viewport() ## requires R 2.1.0 (I believe)
No, I think it's been there for a while. However, AFAIR the fact that viewports have components xscale and yscale that can be accessed like this is undocumented and may change if the implementation changes (which is a real possibility). Ideally, there should be exported interfaces to access this information, either in grid or lattice. One of the reasons there isn't is that you rarely
Yes, I agree that such an interface is quite desirable.
OK, I'll put something in the next version of lattice.
The expression I recommend for this sort of thing is something like ... convertY(unit(0:1, "npc"), "native", valueOnly=TRUE) Paul
Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
Thank all very much for answers. grid.text in the Deepayan's varian did the trick satisfactory. However, at any rate it would be great to have access to the information about viewports, because I would like text not to overlap the graphics. Therefore its placement should be calculated with respect to the values displayed, and it is necessary to know how many free space available in different parts of the viewport. Hopefully, in this particular case all my graphs had enough free space in the upper left corner. -- Best regards Wladimir Eremeev mailto:wl at eimb.ru ========================================================================== Research Scientist, PhD Leninsky Prospect 33, Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071, Institute of Ecology, Phone: (095) 135-9972; Russian Academy of Sciences Fax: (095) 135-9972