I know I can use panel.xyarea
from latticeExtra to fill the area in the plot with any colour. Without defining a type
argument in xyplot
, such filling will follow the route of default type="p"
:
library(lattice)
library(latticeExtra)
data <- data.frame(time=1:24,value=rnorm(24))
xyplot(value~time, data,
panel=function(x,y,...){
panel.xyarea(x,y,...)
panel.xyplot(x,y,...)})
This plots both panel.xyarea
and the points coming from default type="p"
in panel.xyplot
. Now the problem arise when I want to change the type
of plotting line, for example making it step function type="S"
:
xyplot(value~time, data, type="S",
panel=function(x,y,...){
panel.xyarea(x,y,...)
panel.xyplot(x,y,...)}
As you see on the example above, panel.xyarea
doesn't fill the area underneath the new step function, but instead it plots both areas overlapping. It doesn't change anything if I move type="S"
to the panel.xyarea
- in fact it doesn't register type
argument it at all and plots as it wouldn't be there.
Is there a way I can bypass this and have panel.xyarea
fill my plots whatever type I define - be it step function (type="S"
), loess (type="smooth"
) or regression (type="r"
)? Or maybe there is something better than panel.xyarea
to use in such context?