[R] lattice xyplot with cumsum() function inside

2024-09-28 Thread Naresh Gurbuxani


This code gives unexpected result.

library(data.table)
library(lattice)

set.seed(123)
mydt <- data.table(date = seq.Date(as.IDate("2024-01-01"), by = 1,
length.out = 50), xgroup = "A", x = runif(50, 0, 1))
mydt <- rbindlist(list(mydt, data.table(date = mydt$date, xgroup = "B", x = 
runif(50, 0, 3
mydt[, `:=`(xcumsum = cumsum(x)), by = .(xgroup)]
mydt[, lapply(.SD, sum), by = .(xgroup), .SDcols = c("x")]
#   xgroupx
#   
#1:  A 26.00455
#2:  B 71.55405

#For xgroup = "B", line starts at the sum of all previous x values
including xgroup = "A"
#Intended result is to separate cumsum(x) for groups "A" and "B"
mydt[, xyplot(cumsum(x) ~ date, groups = xgroup, type = c("l", "g"))]

mydf <- as.data.frame(mydt)
xyplot(cumsum(x) ~ date, groups = xgroup, type = c("l", "g"), data =
mydf)
#Same graph

aggregate(x ~ xgroup, FUN = sum, data = mydf)
#  xgroupx
#1  A 26.00455
#2  B 71.55405

#In graph, group "A" goes up to 26.  But group "B" goes up to 26 + 71.55

#I can get intended graph in this way
mydt[, xyplot(xcumsum ~ date, groups = xgroup, type = c("l", "g"),
auto.key = list(columns = 2, space = "bottom"))]

Is this a bug or incorrect use of function?

Thanks,
Naresh

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] lattice xyplot: how to change the y-axis labels size using yscale.components.subticks on the right side and how to adapt the ticks number

2023-05-31 Thread Laurent Rhelp

I will try to explain in a bit more detail.

1. I want to have the labels on the right with a small size to be able 
to read them

2. I would like not to have the labels on the left
3.  I would like to be able to choose the number of principal ticks for 
every sensor. That is to say the value of n in the call of 
my_yscale.components.subtick. But I have the impression that n is always 
equal to 5.


To change the n number I tried to do this:

my_yscale.components.subticks <- function (lim, ..., n = 5, n2 = n * 5, 
min.n2 = n + 5)

  {
    n1 <- 10
    n2 <- n1*5
    ans <- yscale.components.default(lim = lim, ...,    n  =  n1 )
    ans2 <- yscale.components.default(lim = lim, ...,  n  =  n2 ,
  min.n = min.n2)
  etc...

It works but the n value is the same for all the sensors.

thank you



Le 30/05/2023 à 20:06, Deepayan Sarkar a écrit :

Thanks for the reproducible example. Could you explain what you want
in a bit more detail? Does the following do more or less what you
want, except that the labels are on the left instead of right?

gr <-
 xyplot(value ~ tindexTOP | sensor
  , data = df_rhelp
  , ylab = " "
  , xlab = list("Time (s)", font=9)
  , main = "test yscale.components with axis"
  , subset = sensor %in% paste0("sensor",1:8)
  , layout = c(1,8)
  , between = list(y = 0.5),
  , scales = list(y = list(relation = "free", cex = 0.3, rot = 0)
, x = list(relation = "same", axs = "i",
   rot = 45, cex = 0.3))
  , type = c("l","g")
  , yscale.components = my_yscale.components.subticks
## , xscale.components = xscale.components.subticks
  , strip = F
  , strip.left = strip.custom(
par.strip.text = list(font=3, cex = 0.5,col="red",lines=3)
)
  , par.strip.text = list(font=3, cex = 0.5,col="red",lines=2)
  , par.settings = list(plot.line  = list(col = "black")
  , strip.background=list(col="transparent")
  , layout.widths = list(axis.key.padding = 5)
))

If you want the same labels on the right as well, you will just need
to uncomment the line

ans$right <- TRUE

in your my_yscale.components.subticks function.

-Deepayan

On Tue, May 30, 2023 at 12:39 AM Laurent Rhelp  wrote:

Dear R-Help-list,

 I want to display many sensors on the same page so I have to adapt
the size of the y-axis labels and I woul like to adapt the number of
ticks according to the sensor. I use the yscale.components argument with
the function yscale.components.subticks: see the code below.

In order to change the size labels on the right I tried to add the line
ans$left$labels$cex <- 0.3 in yscale.components.subticks but it doesn't
work. I try to put cex = 0.3 in the scale argument for the y list but it
doesn't work too.

And since the numeric ranges of sensors are different I would like to
adapt the ticks number for every sensor. But I didn't undestand how to
pass the value of the n argument at the yscale.components function and
how I can use this function according to the current panel.

Thank you

Best regards

Laurent


o<-->o

The data:

df_rhelp <- structure(list(tindexTOP = c(4.76837158203125e-07,
4.76837158203125e-07,
4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
4.76837158203125e-07, 2.86102294921875e-06, 2.86102294921875e-06,
2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
2.86102294921875e-06, 5.48362731933594e-06, 5.48362731933594e-06,
5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
5.48362731933594e-06, 7.86781311035156e-06, 7.86781311035156e-06,
7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
7.86781311035156e-06, 1.04904174804688e-05, 1.04904174804688e-05,
1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
1.04904174804688e-05, 1.28746032714844e-05, 1.28746032714844e-05,
1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
1.28746032714844e-05, 1.54972076416016e-05, 1.54972076416016e-05,
1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
1.54972076416016e-05, 1.78813934326172e-05, 1.78813934326172e-05,
1.78813934326172e-05, 1.78813934326172e-05, 1.78813934326172e-05,
1.78813934326172e-05, 1.78813934326172e-05, 1.788139343261

Re: [R] lattice xyplot: how to change the y-axis labels size using yscale.components.subticks on the right side and how to adapt the ticks number

2023-05-30 Thread Deepayan Sarkar
Thanks for the reproducible example. Could you explain what you want
in a bit more detail? Does the following do more or less what you
want, except that the labels are on the left instead of right?

gr <-
xyplot(value ~ tindexTOP | sensor
 , data = df_rhelp
 , ylab = " "
 , xlab = list("Time (s)", font=9)
 , main = "test yscale.components with axis"
 , subset = sensor %in% paste0("sensor",1:8)
 , layout = c(1,8)
 , between = list(y = 0.5),
 , scales = list(y = list(relation = "free", cex = 0.3, rot = 0)
   , x = list(relation = "same", axs = "i",
  rot = 45, cex = 0.3))
 , type = c("l","g")
 , yscale.components = my_yscale.components.subticks
   ## , xscale.components = xscale.components.subticks
 , strip = F
 , strip.left = strip.custom(
   par.strip.text = list(font=3, cex = 0.5,col="red",lines=3)
   )
 , par.strip.text = list(font=3, cex = 0.5,col="red",lines=2)
 , par.settings = list(plot.line  = list(col = "black")
 , strip.background=list(col="transparent")
 , layout.widths = list(axis.key.padding = 5)
   ))

If you want the same labels on the right as well, you will just need
to uncomment the line

   ans$right <- TRUE

in your my_yscale.components.subticks function.

-Deepayan

On Tue, May 30, 2023 at 12:39 AM Laurent Rhelp  wrote:
>
> Dear R-Help-list,
>
> I want to display many sensors on the same page so I have to adapt
> the size of the y-axis labels and I woul like to adapt the number of
> ticks according to the sensor. I use the yscale.components argument with
> the function yscale.components.subticks: see the code below.
>
> In order to change the size labels on the right I tried to add the line
> ans$left$labels$cex <- 0.3 in yscale.components.subticks but it doesn't
> work. I try to put cex = 0.3 in the scale argument for the y list but it
> doesn't work too.
>
> And since the numeric ranges of sensors are different I would like to
> adapt the ticks number for every sensor. But I didn't undestand how to
> pass the value of the n argument at the yscale.components function and
> how I can use this function according to the current panel.
>
> Thank you
>
> Best regards
>
> Laurent
>
>
> o<-->o
>
> The data:
>
> df_rhelp <- structure(list(tindexTOP = c(4.76837158203125e-07,
> 4.76837158203125e-07,
> 4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
> 4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
> 4.76837158203125e-07, 2.86102294921875e-06, 2.86102294921875e-06,
> 2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
> 2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
> 2.86102294921875e-06, 5.48362731933594e-06, 5.48362731933594e-06,
> 5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
> 5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
> 5.48362731933594e-06, 7.86781311035156e-06, 7.86781311035156e-06,
> 7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
> 7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
> 7.86781311035156e-06, 1.04904174804688e-05, 1.04904174804688e-05,
> 1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
> 1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
> 1.04904174804688e-05, 1.28746032714844e-05, 1.28746032714844e-05,
> 1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
> 1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
> 1.28746032714844e-05, 1.54972076416016e-05, 1.54972076416016e-05,
> 1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
> 1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
> 1.54972076416016e-05, 1.78813934326172e-05, 1.78813934326172e-05,
> 1.78813934326172e-05, 1.78813934326172e-05, 1.78813934326172e-05,
> 1.78813934326172e-05, 1.78813934326172e-05, 1.78813934326172e-05,
> 1.78813934326172e-05, 2.05039978027344e-05, 2.05039978027344e-05,
> 2.05039978027344e-05, 2.05039978027344e-05, 2.05039978027344e-05,
> 2.05039978027344e-05, 2.05039978027344e-05, 2.05039978027344e-05,
> 2.05039978027344e-05, 2.288818359375e-05, 2.288818359375e-05,
> 2.288818359375e-05, 2.288818359375e-05, 2.288818359375e-05,
> 2.288818359375e-05,
> 2.288818359375e-05, 2.288818359375e-05, 2.288818359375e-05,
> 2.55107879638672e-05,
> 2.55107879638672e-05, 2.55107879638672e-05, 2.55107879638672e-05,
> 2.55107879638672e-05, 2.55107879638672e-05, 2.55107879638672e-05,
> 2.55107879638672e-05, 2.55107879638672e-05, 2.78949737548828e-05
> ), sensor = structure(c(3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L,
> 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L,
> 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L

[R] lattice xyplot: how to change the y-axis labels size using yscale.components.subticks on the right side and how to adapt the ticks number

2023-05-29 Thread Laurent Rhelp

Dear R-Help-list,

   I want to display many sensors on the same page so I have to adapt 
the size of the y-axis labels and I woul like to adapt the number of 
ticks according to the sensor. I use the yscale.components argument with 
the function yscale.components.subticks: see the code below.


In order to change the size labels on the right I tried to add the line 
ans$left$labels$cex <- 0.3 in yscale.components.subticks but it doesn't 
work. I try to put cex = 0.3 in the scale argument for the y list but it 
doesn't work too.


And since the numeric ranges of sensors are different I would like to 
adapt the ticks number for every sensor. But I didn't undestand how to 
pass the value of the n argument at the yscale.components function and 
how I can use this function according to the current panel.


Thank you

Best regards

Laurent


o<-->o

The data:

df_rhelp <- structure(list(tindexTOP = c(4.76837158203125e-07, 
4.76837158203125e-07,

4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
4.76837158203125e-07, 2.86102294921875e-06, 2.86102294921875e-06,
2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
2.86102294921875e-06, 5.48362731933594e-06, 5.48362731933594e-06,
5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
5.48362731933594e-06, 7.86781311035156e-06, 7.86781311035156e-06,
7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
7.86781311035156e-06, 1.04904174804688e-05, 1.04904174804688e-05,
1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
1.04904174804688e-05, 1.28746032714844e-05, 1.28746032714844e-05,
1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
1.28746032714844e-05, 1.54972076416016e-05, 1.54972076416016e-05,
1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
1.54972076416016e-05, 1.78813934326172e-05, 1.78813934326172e-05,
1.78813934326172e-05, 1.78813934326172e-05, 1.78813934326172e-05,
1.78813934326172e-05, 1.78813934326172e-05, 1.78813934326172e-05,
1.78813934326172e-05, 2.05039978027344e-05, 2.05039978027344e-05,
2.05039978027344e-05, 2.05039978027344e-05, 2.05039978027344e-05,
2.05039978027344e-05, 2.05039978027344e-05, 2.05039978027344e-05,
2.05039978027344e-05, 2.288818359375e-05, 2.288818359375e-05,
2.288818359375e-05, 2.288818359375e-05, 2.288818359375e-05, 
2.288818359375e-05,
2.288818359375e-05, 2.288818359375e-05, 2.288818359375e-05, 
2.55107879638672e-05,

2.55107879638672e-05, 2.55107879638672e-05, 2.55107879638672e-05,
2.55107879638672e-05, 2.55107879638672e-05, 2.55107879638672e-05,
2.55107879638672e-05, 2.55107879638672e-05, 2.78949737548828e-05
), sensor = structure(c(3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L), levels = c("sensor1",
"sensor2", "sensor3", "sensor4", "sensor5", "sensor6", "sensor7",
"sensor8", "sensor9"), class = "factor"), value = c(-0.0470466909098229,
-0.00706818838871735, 161.436801895656, -172.78672402378, 
-79.9361479857483,

-0.00891825113687091, -0.0448694697768801, 0.712425108966963,
0.401695579543726, -0.00853561853384195, 0.00227566229773253,
161.583962803598, -172.786724022067, -79.8239603415978, 
-0.00977019791023207,
-0.0456647729895611, -0.13262603339186, -1.42342494912657, 
0.0361391588361329,

0.0101823004079, 161.752781180395, -172.786724020224, -79.47940948,
-0.00833297732602559, -0.0452567494314687, -0.345867818702583,
-0.445302124137744, 0.0740098049592515, 0.00668399483148732,
161.820662102699, -172.786724020131, -79.0099113997788, 
-0.0096576618169,
-0.0450868234218926, 0.438855203334293, 1.65859497904806, 
0.0937767405962466,

0.00523329310606791, 161.832971211745, -172.786724019897, -78.53801857597,
-0.00944050307772246, -0.0451963808453651, 0.874052460245523,
1.27714958276318, 0.080325071018673, 0.0105218297802455, 161.828614569151,
-172.786724026001, -78.1829114611251, -0.0096485992190361, 
-0.045410374886218,
0.213898316321324, -0.93396499839784, 0.0415044547581841, 
0.0116075320692717,
161.80458844672, -172.786724021518, -78.0549456280623, 
-0.00891923753973763,
-0.045981616786497, -0.41157010119221, -1.18416730074984, 

Re: [R] lattice xyplot: trouble about the use of yscale.components to start the yscale from zero

2023-01-24 Thread Laurent Rhelp
Thank you very much for the typo !! and the example about the 
consequences.  I did not know about the option warnPartialMatchDollar = 
TRUE, I tested it with my mistake it is very effective indeed. This 
option should be TRUE by default.

I edited my mistake but there is still the trouble, the labels do not 
appear on the y-axis if I keep ylim = c(0,max(lim)). But nevermind 
because your solution to use prepanel works very well and I will think 
next time to use prepanel.

Best regards
L.



Le 22/01/2023 à 18:43, Deepayan Sarkar a écrit :
>
>
> On Sun, Jan 22, 2023 at 6:48 PM Laurent Rhelp  
> wrote:
>
> Dear RHelp-list,
>
>   I want to choice my scale for every panel in a lattice graph
> according to
>   the ylim range of every panel, with 10 ticks and with a start
> from 0.
> Also I want to plot a grid
>    according to the y ticks (I did that in the panel argument with
> the
> panel.abline function) .
>   So I decided to use the yscale.components argument and I write the
> script below.
>   Before using the pretty function I introduce the 0 value in my
> range but
> it does not work : the labels are not displayed and the
> panel.abline do
> nothing. I am not able to understand why.
>    If I comment the line ylim <- c(0,max(lim)) the labels appear
> but of
> course they do not start from 0.
>
>
> You have mistyped
>
>   ans$left$ticks$at <- tick.at 
>
> as
>
>   ans$left$tick$at <- tick.at 
>
> You might think that partial matching will help you, but partial 
> matching doesn't work for assignment (for obvious reasons). Consider
>
> > foo <- list(ticks = list(at = 1:10))
> > foo$tick$at <- "bar"
> > str(foo)
> List of 2
>  $ ticks:List of 1
>   ..$ at: int [1:10] 1 2 3 4 5 6 7 8 9 10
>  $ tick :List of 1
>   ..$ at: chr "bar"
>
> I don't know if there is a good argument for this assignment to work 
> at all (other than that NULL and an empty list are conceptually 
> equivalent), but it is what it is.
>
> This is why I tend to set options(warnPartialMatchDollar = TRUE). In 
> this case it would give you an inaccurate warning, but at least it 
> will give you a warning.
>
> As for the range of the scales, these are determined by 'ylim' and 
> 'prepanel', so you would need to specify one of these.
>
> As you are using scales$axs = "i", you can simply provide ylim = c(0, 
> NA), which forces the lower limit to 0, and lets the upper limit be 
> decided as usual.
>
> For finer control, you can specify a prepanel function, e.g.,
>
> prepanel = function(x, y, ...) list(ylim = c(0, max(y)))
>
> Hope this helps,
>
> Best,
> -Deepayan
>
>
> Thank you for your help.
>
> Laurent
>
>
>   
> --o<--->o-
> library(lattice)
> library(zoo)
> ##
> ## Rq : mydata is a zoo object
> ##
> mydata <- structure(c(0.190991684047867, 0.186639474048368,
> 0.188562286982088,
>  0.187781290093149, 0.188242724296645, 0.190412570465429,
> 0.188922969182772,
>  0.194037520889193, 0.191973884842229, 0.197032138922638,
> 1.03204611806177,
>  1.02831610106898, 1.0280323738983, 1.03595907392095,
> 1.03316162925952,
>  1.04755124287765, 1.04403986225312, 1.05686325668364,
> 1.04672225664295,
>  1.05462971668107), dim = c(10L, 2L), dimnames =
> list(c("f1",
>   "f1", "f1", "f1", "f1", "f1", "f1", "f1", "f1", "f1"),
> c("col1","col2"))
>   , index = c(1.27904891967773, 1.27909898757935,
> 1.27915000915527
>    , 1.27920007705688, 1.2792489528656, 1.27929902076721,
> 1.27935004234314
>    ,1.27939891815186, 1.27944993972778, 1.2795762939),
> class =
> "zoo")
>
> options(digits=17)
>
> yscale.components.n.ticks <- function(lim,...){
>
>    ans <- yscale.components.default(lim = lim,...)
>    ylim <- lim
>    ## I want to start from 0
>    ylim <- c(0,max(lim))
> tick.at  <- pretty(ylim, n=10, min.n = 9)
>     cat("lim yscale : ",ylim,"\n")
>
>    mylabels_y <- formatC( tick.at 
>   , format = "f"
>   , digits=3
>   , width=9
>   ,flag=" ")
>
>    print(cbind( mylabels_y = mylabels_y, tick.at_y = tick.at
> ))
>
>    ans$left$tick$at <- tick.at 
>    ans$left$labels$at <- tick.at 
>    ans$left$labels$labels <- mylabels_y
>    ans
> }
>
>
> xscale.components.n.ticks <- function(lim, ... ){
>
>    ans <- xscale.components.default(lim = lim,...)
> tick.at  <- pretty(lim,20,9)
>    mylabels_x <- formatC( tick.at 
> 

Re: [R] lattice xyplot: trouble about the use of yscale.components to start the yscale from zero

2023-01-22 Thread Deepayan Sarkar
On Sun, Jan 22, 2023 at 6:48 PM Laurent Rhelp  wrote:

> Dear RHelp-list,
>
>   I want to choice my scale for every panel in a lattice graph according to
>   the ylim range of every panel, with 10 ticks and with a start from 0.
> Also I want to plot a grid
>according to the y ticks (I did that in the panel argument with the
> panel.abline function) .
>   So I decided to use the yscale.components argument and I write the
> script below.
>   Before using the pretty function I introduce the 0 value in my range but
> it does not work : the labels are not displayed and the panel.abline do
> nothing. I am not able to understand why.
>If I comment the line ylim <- c(0,max(lim)) the labels appear but of
> course they do not start from 0.
>

You have mistyped

  ans$left$ticks$at <- tick.at

as

  ans$left$tick$at <- tick.at

You might think that partial matching will help you, but partial matching
doesn't work for assignment (for obvious reasons). Consider

> foo <- list(ticks = list(at = 1:10))
> foo$tick$at <- "bar"
> str(foo)
List of 2
 $ ticks:List of 1
  ..$ at: int [1:10] 1 2 3 4 5 6 7 8 9 10
 $ tick :List of 1
  ..$ at: chr "bar"

I don't know if there is a good argument for this assignment to work at all
(other than that NULL and an empty list are conceptually equivalent), but
it is what it is.

This is why I tend to set options(warnPartialMatchDollar = TRUE). In this
case it would give you an inaccurate warning, but at least it will give you
a warning.

As for the range of the scales, these are determined by 'ylim' and
'prepanel', so you would need to specify one of these.

As you are using scales$axs = "i", you can simply provide ylim = c(0, NA),
which forces the lower limit to 0, and lets the upper limit be decided as
usual.

For finer control, you can specify a prepanel function, e.g.,

prepanel = function(x, y, ...) list(ylim = c(0, max(y)))

Hope this helps,

Best,
-Deepayan


>
> Thank you for your help.
>
> Laurent
>
>
>
>   
> --o<--->o-
> library(lattice)
> library(zoo)
> ##
> ## Rq : mydata is a zoo object
> ##
> mydata <- structure(c(0.190991684047867, 0.186639474048368,
> 0.188562286982088,
>  0.187781290093149, 0.188242724296645, 0.190412570465429,
> 0.188922969182772,
>  0.194037520889193, 0.191973884842229, 0.197032138922638,
> 1.03204611806177,
>  1.02831610106898, 1.0280323738983, 1.03595907392095,
> 1.03316162925952,
>  1.04755124287765, 1.04403986225312, 1.05686325668364,
> 1.04672225664295,
>  1.05462971668107), dim = c(10L, 2L), dimnames = list(c("f1",
>   "f1", "f1", "f1", "f1", "f1", "f1", "f1", "f1", "f1"),
> c("col1","col2"))
>   , index = c(1.27904891967773, 1.27909898757935, 1.27915000915527
>, 1.27920007705688, 1.2792489528656, 1.27929902076721,
> 1.27935004234314
>,1.27939891815186, 1.27944993972778, 1.2795762939), class =
> "zoo")
>
> options(digits=17)
>
> yscale.components.n.ticks <- function(lim,...){
>
>ans <- yscale.components.default(lim = lim,...)
>ylim <- lim
>## I want to start from 0
>ylim <- c(0,max(lim))
>tick.at <- pretty(ylim, n=10, min.n = 9)
> cat("lim yscale : ",ylim,"\n")
>
>mylabels_y <- formatC(   tick.at
>   , format = "f"
>   , digits=3
>   , width=9
>   ,flag=" ")
>
>print(cbind( mylabels_y = mylabels_y, tick.at_y = tick.at))
>
>ans$left$tick$at <- tick.at
>ans$left$labels$at <- tick.at
>ans$left$labels$labels <- mylabels_y
>ans
> }
>
>
> xscale.components.n.ticks <- function(lim, ... ){
>
>ans <- xscale.components.default(lim = lim,...)
>tick.at <- pretty(lim,20,9)
>mylabels_x <- formatC(   tick.at
>   , format = "f"
>   , digits=6
>   , width=9
>   , flag=" ")
>
>print(cbind( mylabels_x = mylabels_x, tick.at_x = tick.at))
>
>ans$bottom$tick$at <- tick.at
>ans$bottom$labels$at <- tick.at
>ans$bottom$labels$labels <- mylabels_x
>ans
> }
>
> # to see the x values
> time(mydata)
>
> gr <- xyplot(  mydata
> , main = "title"
> , layout = c(1,2)
> , pch = 20
> , panel = function(...) {
>
>   ylim <- current.panel.limits()$ylim
>   xlim <- current.panel.limits()$xlim
>
>   ## I create here the same ticks that those created
>   ##  in xscale.components and yscale.components
>  ylim <- c(0,max(ylim))
>  cat("ylim panel : ",ylim,"\n")
>  y.tick.at <- pretty(ylim,10,9)
>  print(cbind(y.tick.at.panel= y.tick.at))
>
>   x.tick.at <- pretty(xlim,20,9)
>
>  panel.abline( h

[R] lattice xyplot: trouble about the use of yscale.components to start the yscale from zero

2023-01-22 Thread Laurent Rhelp

Dear RHelp-list,

 I want to choice my scale for every panel in a lattice graph according to
 the ylim range of every panel, with 10 ticks and with a start from 0. 
Also I want to plot a grid
  according to the y ticks (I did that in the panel argument with the 
panel.abline function) .
 So I decided to use the yscale.components argument and I write the 
script below.

 Before using the pretty function I introduce the 0 value in my range but
it does not work : the labels are not displayed and the panel.abline do 
nothing. I am not able to understand why.
  If I comment the line ylim <- c(0,max(lim)) the labels appear but of 
course they do not start from 0.


Thank you for your help.

Laurent


 
--o<--->o-
library(lattice)
library(zoo)
##
## Rq : mydata is a zoo object
##
mydata <- structure(c(0.190991684047867, 0.186639474048368, 
0.188562286982088,
    0.187781290093149, 0.188242724296645, 0.190412570465429, 
0.188922969182772,
    0.194037520889193, 0.191973884842229, 0.197032138922638, 
1.03204611806177,
    1.02831610106898, 1.0280323738983, 1.03595907392095, 
1.03316162925952,
    1.04755124287765, 1.04403986225312, 1.05686325668364, 
1.04672225664295,

    1.05462971668107), dim = c(10L, 2L), dimnames = list(c("f1",
 "f1", "f1", "f1", "f1", "f1", "f1", "f1", "f1", "f1"), 
c("col1","col2"))

 , index = c(1.27904891967773, 1.27909898757935, 1.27915000915527
  , 1.27920007705688, 1.2792489528656, 1.27929902076721, 
1.27935004234314
  ,1.27939891815186, 1.27944993972778, 1.2795762939), class = 
"zoo")


options(digits=17)

yscale.components.n.ticks <- function(lim,...){

  ans <- yscale.components.default(lim = lim,...)
  ylim <- lim
  ## I want to start from 0
  ylim <- c(0,max(lim))
  tick.at <- pretty(ylim, n=10, min.n = 9)
   cat("lim yscale : ",ylim,"\n")

  mylabels_y <- formatC(   tick.at
 , format = "f"
 , digits=3
 , width=9
 ,flag=" ")

  print(cbind( mylabels_y = mylabels_y, tick.at_y = tick.at))

  ans$left$tick$at <- tick.at
  ans$left$labels$at <- tick.at
  ans$left$labels$labels <- mylabels_y
  ans
}


xscale.components.n.ticks <- function(lim, ... ){

  ans <- xscale.components.default(lim = lim,...)
  tick.at <- pretty(lim,20,9)
  mylabels_x <- formatC(   tick.at
 , format = "f"
 , digits=6
 , width=9
 , flag=" ")

  print(cbind( mylabels_x = mylabels_x, tick.at_x = tick.at))

  ans$bottom$tick$at <- tick.at
  ans$bottom$labels$at <- tick.at
  ans$bottom$labels$labels <- mylabels_x
  ans
}

# to see the x values
time(mydata)

gr <- xyplot(  mydata
   , main = "title"
   , layout = c(1,2)
   , pch = 20
   , panel = function(...) {

 ylim <- current.panel.limits()$ylim
 xlim <- current.panel.limits()$xlim

 ## I create here the same ticks that those created
 ##  in xscale.components and yscale.components
    ylim <- c(0,max(ylim))
    cat("ylim panel : ",ylim,"\n")
    y.tick.at <- pretty(ylim,10,9)
    print(cbind(y.tick.at.panel= y.tick.at))

 x.tick.at <- pretty(xlim,20,9)

    panel.abline( h = y.tick.at, v = x.tick.at, col = 
"lightgrey")


 panel.xyplot(...)
   }
##   , ylim = c(0,1.5)
   , scales = list(
 y= list(   relation = "free"
  , axs="i"
  , rot = 45
  ),
 x = list(
 axs="i"
   , rot = 90
  )
   )
   , yscale.components = yscale.components.n.ticks
   , xscale.components = xscale.components.n.ticks

)

print(gr)

--
Cet e-mail a été vérifié par le logiciel antivirus d'Avast.
www.avast.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot

2017-05-01 Thread array chip via R-help
Thanks all for the clarification!

  From: Jeff Newmiller 
 To: r-help@r-project.org; Bert Gunter ; array chip 
 
Cc: "r-help@r-project.org" 
 Sent: Monday, May 1, 2017 10:53 AM
 Subject: Re: [R] Lattice xyplot
   
It is not a question of whether lattice "understands" the unsorted data... 
imagine trying to plot 4 points to form a square instead of a trend line... you 
would NOT want lattice to sort those points for you. That lattice leaves your 
data alone gives you more flexibility, even while it adds work for certain 
applications. 

-- 
Sent from my phone. Please excuse my brevity.

On May 1, 2017 7:34:09 AM PDT, Bert Gunter  wrote:
>Yes. type = "l" connects the points in the order given in the data, so
>if the x's are not already ordered, the plots will be different after
>ordering the x's.
>
>e.g.
>
>> x <- c(3,1,2,4,6,5)
>> y <- 11:16
>> xyplot(y~x. type = "l")
>
>
>As for why ... that's just the way it was designed. You can always
>order the data first, if you don't want this default.
>
>Cheers,
>Bert
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help
> wrote:
>> Dear all, I am new to lattice, so would appreciate anyone's help on
>the questions below. I am using xyplot to plot some trend in my
>dataset. Using the example dataset attached, I am trying to plot
>variable "y" over variable "time" for each subject "id":
>> dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
>> xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p",
>"l"),  xlab = "Time", ylab = "Y")
>>
>> It appears that it just worked fine. But if I sort the "dat" first,
>the plot will look somewhat different!
>> dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat,
>groups=id, aspect = "fill", type = c("p", "l"),  xlab = "Time", ylab =
>"Y")
>> Why is that? Do you need to sort the data first before using xyplot?
>Why xyplot can not understand the dataset unless it is sorted first?
>> Thanks,
>> John
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.

   
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Lattice xyplot

2017-05-01 Thread peter dalgaard

> On 1 May 2017, at 17:59 , Bert Gunter  wrote:
> 
> (Too trivial for the list)

...so you decided to include us only once? >;-)

-pd

> 
> I debated saying something similar but decided not to, as polygons can
> be drawn e.g. via panel.polygon.
> 
> Cheers,
> Bert
> 
> 
> 
> 
> On Mon, May 1, 2017 at 8:25 AM, Jeff Newmiller  
> wrote:
>> It is not a question of whether lattice "understands" the unsorted data... 
>> imagine trying to plot 4 points to form a square instead of a trend line... 
>> you would NOT want lattice to sort those points for you. That lattice leaves 
>> your data alone gives you more flexibility, even while it adds work for 
>> certain applications.
>> 
>> --
>> Sent from my phone. Please excuse my brevity.
>> 
>> On May 1, 2017 7:34:09 AM PDT, Bert Gunter  wrote:
>>> Yes. type = "l" connects the points in the order given in the data, so
>>> if the x's are not already ordered, the plots will be different after
>>> ordering the x's.
>>> 
>>> e.g.
>>> 
 x <- c(3,1,2,4,6,5)
 y <- 11:16
 xyplot(y~x. type = "l")
>>> 
>>> 
>>> As for why ... that's just the way it was designed. You can always
>>> order the data first, if you don't want this default.
>>> 
>>> Cheers,
>>> Bert
>>> 
>>> Bert Gunter
>>> 
>>> "The trouble with having an open mind is that people keep coming along
>>> and sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>> 
>>> 
>>> On Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help
>>>  wrote:
 Dear all, I am new to lattice, so would appreciate anyone's help on
>>> the questions below. I am using xyplot to plot some trend in my
>>> dataset. Using the example dataset attached, I am trying to plot
>>> variable "y" over variable "time" for each subject "id":
 dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
 xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p",
>>> "l"),  xlab = "Time", ylab = "Y")
 
 It appears that it just worked fine. But if I sort the "dat" first,
>>> the plot will look somewhat different!
 dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat,
>>> groups=id, aspect = "fill", type = c("p", "l"),  xlab = "Time", ylab =
>>> "Y")
 Why is that? Do you need to sort the data first before using xyplot?
>>> Why xyplot can not understand the dataset unless it is sorted first?
 Thanks,
 John
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot

2017-05-01 Thread Bert Gunter
(Too trivial for the list)

I debated saying something similar but decided not to, as polygons can
be drawn e.g. via panel.polygon.

Cheers,
Bert




On Mon, May 1, 2017 at 8:25 AM, Jeff Newmiller  wrote:
> It is not a question of whether lattice "understands" the unsorted data... 
> imagine trying to plot 4 points to form a square instead of a trend line... 
> you would NOT want lattice to sort those points for you. That lattice leaves 
> your data alone gives you more flexibility, even while it adds work for 
> certain applications.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> On May 1, 2017 7:34:09 AM PDT, Bert Gunter  wrote:
>>Yes. type = "l" connects the points in the order given in the data, so
>>if the x's are not already ordered, the plots will be different after
>>ordering the x's.
>>
>>e.g.
>>
>>> x <- c(3,1,2,4,6,5)
>>> y <- 11:16
>>> xyplot(y~x. type = "l")
>>
>>
>>As for why ... that's just the way it was designed. You can always
>>order the data first, if you don't want this default.
>>
>>Cheers,
>>Bert
>>
>>Bert Gunter
>>
>>"The trouble with having an open mind is that people keep coming along
>>and sticking things into it."
>>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>>On Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help
>> wrote:
>>> Dear all, I am new to lattice, so would appreciate anyone's help on
>>the questions below. I am using xyplot to plot some trend in my
>>dataset. Using the example dataset attached, I am trying to plot
>>variable "y" over variable "time" for each subject "id":
>>> dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
>>> xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p",
>>"l"),  xlab = "Time", ylab = "Y")
>>>
>>> It appears that it just worked fine. But if I sort the "dat" first,
>>the plot will look somewhat different!
>>> dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat,
>>groups=id, aspect = "fill", type = c("p", "l"),  xlab = "Time", ylab =
>>"Y")
>>> Why is that? Do you need to sort the data first before using xyplot?
>>Why xyplot can not understand the dataset unless it is sorted first?
>>> Thanks,
>>> John
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>>__
>>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot

2017-05-01 Thread Jeff Newmiller
It is not a question of whether lattice "understands" the unsorted data... 
imagine trying to plot 4 points to form a square instead of a trend line... you 
would NOT want lattice to sort those points for you. That lattice leaves your 
data alone gives you more flexibility, even while it adds work for certain 
applications. 

-- 
Sent from my phone. Please excuse my brevity.

On May 1, 2017 7:34:09 AM PDT, Bert Gunter  wrote:
>Yes. type = "l" connects the points in the order given in the data, so
>if the x's are not already ordered, the plots will be different after
>ordering the x's.
>
>e.g.
>
>> x <- c(3,1,2,4,6,5)
>> y <- 11:16
>> xyplot(y~x. type = "l")
>
>
>As for why ... that's just the way it was designed. You can always
>order the data first, if you don't want this default.
>
>Cheers,
>Bert
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help
> wrote:
>> Dear all, I am new to lattice, so would appreciate anyone's help on
>the questions below. I am using xyplot to plot some trend in my
>dataset. Using the example dataset attached, I am trying to plot
>variable "y" over variable "time" for each subject "id":
>> dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
>> xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p",
>"l"),  xlab = "Time", ylab = "Y")
>>
>> It appears that it just worked fine. But if I sort the "dat" first,
>the plot will look somewhat different!
>> dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat,
>groups=id, aspect = "fill", type = c("p", "l"),  xlab = "Time", ylab =
>"Y")
>> Why is that? Do you need to sort the data first before using xyplot?
>Why xyplot can not understand the dataset unless it is sorted first?
>> Thanks,
>> John
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot

2017-05-01 Thread Duncan Mackay
In addition to Berts comments

Once you change the order you change the non factored  id' ordering. If you 
make it a factor it may be  easier to see what is going on
I think I have copied correctly - see the differences 

# original data
xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")
# order
dat2<-dat[order(dat$id, dat$time),]
xyplot(y ~ time, data=dat2, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")
# make ID a factor
dat3 <- dat1
xyplot(y ~ time, data=dat3, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")
# ordered + ID a factor
dat4 <- dat3
dat4<-dat[order(dat4$id, dat4$time),]
xyplot(y ~ time, data=dat4, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of array chip via 
R-help
Sent: Monday, 1 May 2017 11:07
To: r-help@r-project.org
Subject: [R] Lattice xyplot

Dear all, I am new to lattice, so would appreciate anyone's help on the 
questions below. I am using xyplot to plot some trend in my dataset. Using the 
example dataset attached, I am trying to plot variable "y" over variable "time" 
for each subject "id":
dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")

It appears that it just worked fine. But if I sort the "dat" first, the plot 
will look somewhat different!
dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, aspect 
= "fill", type = c("p", "l"),  xlab = "Time", ylab = "Y")
Why is that? Do you need to sort the data first before using xyplot? Why xyplot 
can not understand the dataset unless it is sorted first?
Thanks,
John

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot

2017-05-01 Thread Bert Gunter
Yes. type = "l" connects the points in the order given in the data, so
if the x's are not already ordered, the plots will be different after
ordering the x's.

e.g.

> x <- c(3,1,2,4,6,5)
> y <- 11:16
> xyplot(y~x. type = "l")


As for why ... that's just the way it was designed. You can always
order the data first, if you don't want this default.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help
 wrote:
> Dear all, I am new to lattice, so would appreciate anyone's help on the 
> questions below. I am using xyplot to plot some trend in my dataset. Using 
> the example dataset attached, I am trying to plot variable "y" over variable 
> "time" for each subject "id":
> dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
> xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"),  
> xlab = "Time", ylab = "Y")
>
> It appears that it just worked fine. But if I sort the "dat" first, the plot 
> will look somewhat different!
> dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, 
> aspect = "fill", type = c("p", "l"),  xlab = "Time", ylab = "Y")
> Why is that? Do you need to sort the data first before using xyplot? Why 
> xyplot can not understand the dataset unless it is sorted first?
> Thanks,
> John
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Lattice xyplot

2017-05-01 Thread array chip via R-help
Dear all, I am new to lattice, so would appreciate anyone's help on the 
questions below. I am using xyplot to plot some trend in my dataset. Using the 
example dataset attached, I am trying to plot variable "y" over variable "time" 
for each subject "id":
dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")

It appears that it just worked fine. But if I sort the "dat" first, the plot 
will look somewhat different!
dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, aspect 
= "fill", type = c("p", "l"),  xlab = "Time", ylab = "Y")
Why is that? Do you need to sort the data first before using xyplot? Why xyplot 
can not understand the dataset unless it is sorted first?
Thanks,
Johnid  timey
107 0   6.5
107 1   5.1
107 2   4.2
112 0   5.6
107 3   6.9
112 1   4
112 2   1
119 0   7.6
112 3   4.9
119 1   5.7
120 0   7.1
203 0   7.4
120 2   2.1
203 1   6.3
123 0   6.8
203 2   3.8
119 3   6.1
123 1   3.9
123 2   3
120 3   6
203 3   7.6
207 0   5.8
207 1   3.1
123 3   5.7
209 3   3.6
208 0   4.4
130 0   5.5
131 0   6.9
133 0   5.7
134 0   5.1
209 0   4.9
128 2   2.9
128 1   4.5
130 2   5.9
131 1   6.9
133 2   2.6
133 1   5.7
403 2   3.1
403 0   4.5
128 0   4.5
134 2   2.3
207 3   4.8
130 3   4.9
207 2   2.3
130 1   3.8
131 2   3.9
133 3   3.1
134 1   2.8
209 1   4.2
208 3   2.3
208 1   5.3
208 2   0.8
128 3   4.4
131 3   6.2
209 2   5.7
134 3   4.1
403 3   2.5
119 2   2.3
120 1   3.8
403 1   3.2
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Lattice xyplot(): adding a legend [RESOLVED]

2016-10-20 Thread Rich Shepard

On Thu, 20 Oct 2016, David Winsemius wrote:


Why are you creating this factor? The `date` column has the desirable
properties associated with the "Date" class. Axis labeling will be
correct.


David, et al.:

  Because originally I mis-understood the parameters; it's gone now.


rainbyday2 <- xyplot(amount ~ date, data = rain, main = "Area Precipitation",
  ylab = "Daily Total Amount (in)", xlab = "Date",
  scales = list(x=list(at=rain$date[ c(1,8,15,22,29,36,43,50,57,62)], rot = 90),
  y = list(at=c(min(rain$amount), max(rain$amount,
  pch = 20,
  col = c("black","red","dark green","dark blue","dark 
goldenrod","purple")[rain$station],
# Needed to use the 'station'-factor to properly index the colors. Otherwise 
there is no 1-1 relationship.
  key = list( text=list(levels(rain$station)),
  fill = 
c("black","red","darkgreen","darkblue","darkgoldenrod","purple"),
  pch = 16,
x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE)); print(rainbyday2)


  I was getting close to this by stripping the xyplot() code to basics and
adding one element at a time. I removed the scales component and let xyplot
assign the date and quantity labels by default. You filled in the last piece
with the station factor.

  The symbols for the key using 'fill' are all black circles. Changing that
option to 'col' displays both station name and circles in the stated colors.
That makes it much easier to identify individual data points.

  Next time I'll do much better on my own and will research my saved
threads, search for mail list archived threads, and more closely read the
help pages for functions.


Reading the archives shows that this is not the first time this problem of
getting fills with the `key` parameter for xyplot has caused problems for
you. Back in 2013 Richard Heiberger and S Ellison were your
correspondents. I found that using `simpleKey` was unsuccessful due to
problematic defaults.


  And that was the last time I used R for a project. Not all my projects
require R, GRASS, PostgreSQL, or other technical software so I am not a
constant user of any, other than LaTeX.

Many thanks for your patient help,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot(): adding a legend

2016-10-20 Thread David Winsemius

> On Oct 20, 2016, at 9:20 AM, Rich Shepard  wrote:
> 
> On Wed, 19 Oct 2016, David Winsemius wrote:
> 
>> I am getting annoyed, exhausted, and frustrated reading code like that.
>> Never, ever, ... ever, use the "$" operator in a formula. Use the 'data'
>> argument and the 'formula' as they are supposed to be used.
> 
> David,
> 
>  I apologize for annoying, exhausting, and frustrating you. It is not my
> intent and I learned to use the data argument and not the "$" operator a
> while ago. I have not be able to find why that's not working here.
> 
>  Following the 'usage' section in ?xyplot I specify 'x'/'formula' followed
> by the data specification. When I omit the "$" operator R (version 3.3.1)
> displays an empty device window and an error message (shown below the source
> file). The dput() file is attached and the script presented here:
> 
> 
> # This scatter plot displays amount by day for each station, distinguished
> # by color. 'plot-rain-by-date.R'
> 
> # load rain data file
> rain <- read.table("daily_records.dat", header = TRUE, sep = ",", quote = 
> "\"\"")
> rain$date <- as.Date(rain$date)
> 
> # Create a factor from the date
> raindate <- as.factor(rain$date)

Why are you creating this factor? The `date` column has the desirable 
properties associated with the "Date" class. Axis labeling will be correct.


> 
> # Save original plotting parameters
> opar <- par(xpd=NA,no.readonly=T)
> 
> # Prepare the plot of the data
> rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area 
> Precipitation",

#This should have succeeded (.. had you used the dataframe as a data delivery 
vehicle.)

rainbyday <- xyplot( amount ~ date, data = rain, ...)



>ylab = "Daily Total Amount (in)", xlab = "Date",
>scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), 
> rot = 90),
>y = list(at=c(min(rain$amount), max(rain$amount,
>pch = 20,
>col = c("black","red","dark green","dark blue","dark 
> goldenrod","dark magenta"),

Unless you map those colors to the 'station' vector (as I demonstrated in a 
earlier reply, the coloring of the points will be arbitrary. 

>key = simpleKey(text = levels(rain$station)[1:6],
>x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE),
>par.settings = list(plot.symbol = 
> list(c("black","red","dark green","dark blue",
>"dark goldenrod","dark magenta"),

Unless you map those colors to the levels of 'station' as I earlier 
demonstrated, the coloring in the legend will be arbitrary.


> pch = 20, cex = 1.2)))
> 
> # Plot it
> plot(rainbyday)
> 
> # Reset display parameters
> par(opar)
> -
> 
>  When I eliminate the "$" operator this is the error message:
>> source("plot-rain-by-day.R")

We don't have any way of viewing that code. I feel confident it has an error:

Here is code that I believe gives the correct labeling and coloring of points 
and legend. It took some experimentation to get the points in the legend to 
fill correctly:

rainbyday2 <- xyplot(amount ~ date, data = rain, main = "Area Precipitation",
   ylab = "Daily Total Amount (in)", xlab = "Date",
   scales = list(x=list(at=rain$date[ c(1,8,15,22,29,36,43,50,57,62)], rot = 
90),
   y = list(at=c(min(rain$amount), max(rain$amount,
   pch = 20,
   col = c("black","red","dark green","dark blue","dark 
goldenrod","purple")[rain$station], 
 # Needed to use the 'station'-factor to properly index the colors. Otherwise 
there is no 1-1 relationship.
   key = list( text=list(levels(rain$station)), 
   fill = 
c("black","red","darkgreen","darkblue","darkgoldenrod","purple"),
   pch = 16,
 x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE)); print(rainbyday2)


Reading the archives shows that this is not the first time this problem of 
getting fills with the `key` parameter for xyplot has caused problems for you. 
Back in 2013 Richard Heiberger and S Ellison were your correspondents. I found 
that using `simpleKey` was unsuccessful due to problematic defaults.

http://markmail.org/search/?q=list%3Aorg.r-project.r-help+lattice+key+filled+points#query:list%3Aorg.r-project.r-help%20lattice%20key%20filled%20points+page:1+mid:3wbw2rs22uek6okp+state:results


> Error in xyplot.formula(amount ~ raindate, data = rain, main =
> "Area Precipitation",  (from plot-rain-by-day.R#14) :
>  object 'amount' not found

> 
>  The "$" operator appears 4 times; removing any one (or all) of them
> produces the same not found error. If there's another syntax error in the
> xyplot() call, or a logic error in the script please show me my mistake.
> 
>  With the "$" operator there's no error, but the key does not use pch=20;
> have I mis-placed Duncan's suggested par.settings?
> 
> Rich
> 
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE a

Re: [R] Lattice xyplot(): adding a legend

2016-10-20 Thread Bert Gunter
1. Your par(), opar() business is junk -- lattice displays do not use or
modify these. See ?trellis.par.set .

2. You do *not* need rain$ in your formula with the data=rain argument; you
*do* need it in the at argument and elsewhere. The data argument only
controls where the variables in the formula (or subset or group) are
evaluated. This is clearly stated in ?xyplot. Did you read it?

If that doesn't work, your data are screwed up. Incidentally, I counted 3
times where rain$ appears, not 4. Did I miss one or did you err?

3. *Please* reread the key documentation in xyplot carefully. The key
parameters are determined by the points, etc component lists of the key.
The par.settings list controls the **plot** settings.

Finally, are you sure you want date as a factor? Wouldn't that get the date
order all messed up?

Please note that all of this is clearly documented. It's terse, but it's
there. You need to pay careful attention, and then you,David, and everyone
else will be happy and free of frustration.

Bert

On Oct 20, 2016 6:21 PM, "Rich Shepard"  wrote:

> On Wed, 19 Oct 2016, David Winsemius wrote:
>
> I am getting annoyed, exhausted, and frustrated reading code like that.
>> Never, ever, ... ever, use the "$" operator in a formula. Use the 'data'
>> argument and the 'formula' as they are supposed to be used.
>>
>
> David,
>
>   I apologize for annoying, exhausting, and frustrating you. It is not my
> intent and I learned to use the data argument and not the "$" operator a
> while ago. I have not be able to find why that's not working here.
>
>   Following the 'usage' section in ?xyplot I specify 'x'/'formula' followed
> by the data specification. When I omit the "$" operator R (version 3.3.1)
> displays an empty device window and an error message (shown below the
> source
> file). The dput() file is attached and the script presented here:
>
> 
> # This scatter plot displays amount by day for each station, distinguished
> # by color. 'plot-rain-by-date.R'
>
> # load rain data file
> rain <- read.table("daily_records.dat", header = TRUE, sep = ",", quote =
> "\"\"")
> rain$date <- as.Date(rain$date)
>
> # Create a factor from the date
> raindate <- as.factor(rain$date)
>
> # Save original plotting parameters
> opar <- par(xpd=NA,no.readonly=T)
>
> # Prepare the plot of the data
> rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area
> Precipitation",
> ylab = "Daily Total Amount (in)", xlab = "Date",
> scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62),
> rot = 90),
> y = list(at=c(min(rain$amount),
> max(rain$amount,
> pch = 20,
> col = c("black","red","dark green","dark blue","dark
> goldenrod","dark magenta"),
> key = simpleKey(text = levels(rain$station)[1:6],
> x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE),
> par.settings = list(plot.symbol =
> list(c("black","red","dark green","dark blue",
> "dark goldenrod","dark
> magenta"), pch = 20, cex = 1.2)))
>
> # Plot it
> plot(rainbyday)
>
> # Reset display parameters
> par(opar)
> -
>
>   When I eliminate the "$" operator this is the error message:
>
>> source("plot-rain-by-day.R")
>>
> Error in xyplot.formula(amount ~ raindate, data = rain, main =
>  "Area Precipitation",  (from plot-rain-by-day.R#14) :
>   object 'amount' not found
>
>   The "$" operator appears 4 times; removing any one (or all) of them
> produces the same not found error. If there's another syntax error in the
> xyplot() call, or a logic error in the script please show me my mistake.
>
>   With the "$" operator there's no error, but the key does not use pch=20;
> have I mis-placed Duncan's suggested par.settings?
>
> Rich
>
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot(): adding a legend

2016-10-20 Thread Rich Shepard

On Wed, 19 Oct 2016, David Winsemius wrote:


I am getting annoyed, exhausted, and frustrated reading code like that.
Never, ever, ... ever, use the "$" operator in a formula. Use the 'data'
argument and the 'formula' as they are supposed to be used.


David,

  I apologize for annoying, exhausting, and frustrating you. It is not my
intent and I learned to use the data argument and not the "$" operator a
while ago. I have not be able to find why that's not working here.

  Following the 'usage' section in ?xyplot I specify 'x'/'formula' followed
by the data specification. When I omit the "$" operator R (version 3.3.1)
displays an empty device window and an error message (shown below the source
file). The dput() file is attached and the script presented here:


# This scatter plot displays amount by day for each station, distinguished
# by color. 'plot-rain-by-date.R'

# load rain data file
rain <- read.table("daily_records.dat", header = TRUE, sep = ",", quote = 
"\"\"")
rain$date <- as.Date(rain$date)

# Create a factor from the date
raindate <- as.factor(rain$date)

# Save original plotting parameters
opar <- par(xpd=NA,no.readonly=T)

# Prepare the plot of the data
rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area 
Precipitation",
ylab = "Daily Total Amount (in)", xlab = "Date",
scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot 
= 90),
y = list(at=c(min(rain$amount), max(rain$amount,
pch = 20,
col = c("black","red","dark green","dark blue","dark 
goldenrod","dark magenta"),
key = simpleKey(text = levels(rain$station)[1:6],
x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE),
par.settings = list(plot.symbol = list(c("black","red","dark 
green","dark blue",
"dark goldenrod","dark magenta"), 
pch = 20, cex = 1.2)))

# Plot it
plot(rainbyday)

# Reset display parameters
par(opar)
-

  When I eliminate the "$" operator this is the error message:

source("plot-rain-by-day.R")

Error in xyplot.formula(amount ~ raindate, data = rain, main =
 "Area Precipitation",  (from plot-rain-by-day.R#14) :
  object 'amount' not found

  The "$" operator appears 4 times; removing any one (or all) of them
produces the same not found error. If there's another syntax error in the
xyplot() call, or a logic error in the script please show me my mistake.

  With the "$" operator there's no error, but the key does not use pch=20;
have I mis-placed Duncan's suggested par.settings?

Rich


structure(list(station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("0.3E", 
"0.6W", "1..0WNW", "1.5N", "4.3WNW", "Airport"), class = "factor"), 
date = structure(c(32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 
40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 
52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 1L, 
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60

Re: [R] Lattice xyplot(): adding a legend

2016-10-19 Thread David Winsemius

> On Oct 19, 2016, at 4:04 PM, Rich Shepard  wrote:
> 
> On Wed, 19 Oct 2016, Rich Shepard wrote:
> 
>> I did read that but mis-applied what I read. Tried auto.key but that did
>> not work as desired. Now I know to learn how to apply 'key'.
> 
>  Almost there after another careful reading Section 9.2.3 ff in the book.
> Here's the command to produce the plot:
> 
> rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area 
> Precipitation",

I am getting annoyed, exhausted, and frustrated reading code like that. Never, 
ever, ... ever,  use the "$" operator in a formula.

Use the 'data' argument and the 'formula' as they are supposed to be used.



>ylab = "Daily Total Amount (in)", xlab = "Date",
>scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
>y = list(at=c(min(rain$amount), max(rain$amount,
>pch = 20,
>col = c("black","red","dark green","dark blue","dark goldenrod","purple"),

> cl <- colors()
 
> which(cl=="dark goldenrod")
integer(0)
> which(cl=="darkgoldenrod")
[1] 75

Admittedly the error message was completely opaque.


>key = simpleKey(text = levels(rain$station)[1:6],



>  x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE))
> 
>  My question is how to pass pch = 20 to the key. simpleKey accepts only the
> logical TRUE as an argument and this produces a plot with filled circles for
> the data but unfilled circles for the key. I find no example of specifying
> pch for points in the key in either the book or ?xyplot, and I'm sure there
> is a way of having the key symbols match both pch and color as the data
> symbols.
> 

rainbyday <- xyplot(amount ~ raindate, data = rain, main = "Area Precipitation",
   ylab = "Daily Total Amount (in)", xlab = "Date",
   scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
   y = list(at=c(min(rain$amount), max(rain$amount,
   pch = 20,
   col = c("black","red","dark green","dark blue","dark 
goldenrod","purple")[rain$station],
# Note: the need to "pick" the colors from a palette with a vector.
   key = simpleKey( text=as.character( unique(rain$station )), 
   col = 
c("black","red","darkgreen","darkblue","darkgoldenrod","purple"),
   pch = 20,
 x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE)); print(rainbyday)


>  Is use of Rows() the solution?

I am unaware of any 'Rows" function.

> 
> Rich
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot(): adding a legend

2016-10-19 Thread Duncan Mackay
I had not seen Davids reply so will add to my note

The legend is for special keys or multiple keys

eg
https://stat.ethz.ch/pipermail/r-help/2010-May/240341.html

It may involve draw.key()

Duncan

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
Mackay
Sent: Thursday, 20 October 2016 16:11
To: R
Subject: Re: [R] Lattice xyplot(): adding a legend

Hi Rich

Without an example to check I think you need to fill in the arguments for
par.settings eg 

par.settings = list(plot.symbol = list(c("black","red","dark green","dark
blue","dark goldenrod","purple"),
pch
= 20,
   cex =
1),
if you have groups 

par.settings = list(superpose.symbol = list(c("black","red","dark
green","dark blue","dark goldenrod","purple"),
 
pch = 20,
 
cex = 1)),

For other types such as barchart  type 
barchart  and at the top there is

plot.symbol <- trellis.par.get("plot.symbol")
plot.line <- trellis.par.get("plot.line")
superpose.symbol <- trellis.par.get("superpose.symbol")
superpose.line <- trellis.par.get("superpose.line")

Similar occurs for panel.xyplot

I find that ? xyplot  and ?panel. ... give the most uptodate methods things
change overtime.
There are some words on how information is passed to the key in ?xyplot
You either have to set trellis.par.set() or use the par.settings arguments

For older versions things may be slightly different.

If in a hurry I try the easiest but if that fails on the first go I just use
key = list(text = ... etc
 
Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard
Sent: Thursday, 20 October 2016 10:05
To: r-help@r-project.org
Subject: Re: [R] Lattice xyplot(): adding a legend

On Wed, 19 Oct 2016, Rich Shepard wrote:

>  I did read that but mis-applied what I read. Tried auto.key but that did
> not work as desired. Now I know to learn how to apply 'key'.

   Almost there after another careful reading Section 9.2.3 ff in the book.
Here's the command to produce the plot:

rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area
Precipitation",
 ylab = "Daily Total Amount (in)", xlab = "Date",
 scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
 y = list(at=c(min(rain$amount), max(rain$amount,
 pch = 20,
 col = c("black","red","dark green","dark blue","dark
goldenrod","purple"),
 key = simpleKey(text = levels(rain$station)[1:6],
   x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE))

   My question is how to pass pch = 20 to the key. simpleKey accepts only
the
logical TRUE as an argument and this produces a plot with filled circles for
the data but unfilled circles for the key. I find no example of specifying
pch for points in the key in either the book or ?xyplot, and I'm sure there
is a way of having the key symbols match both pch and color as the data
symbols.

   Is use of Rows() the solution?

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot(): adding a legend

2016-10-19 Thread Duncan Mackay
Hi Rich

Without an example to check I think you need to fill in the arguments for
par.settings eg 

par.settings = list(plot.symbol = list(c("black","red","dark green","dark
blue","dark goldenrod","purple"),
pch
= 20,
   cex =
1),
if you have groups 

par.settings = list(superpose.symbol = list(c("black","red","dark
green","dark blue","dark goldenrod","purple"),
 
pch = 20,
 
cex = 1)),

For other types such as barchart  type 
barchart  and at the top there is

plot.symbol <- trellis.par.get("plot.symbol")
plot.line <- trellis.par.get("plot.line")
superpose.symbol <- trellis.par.get("superpose.symbol")
superpose.line <- trellis.par.get("superpose.line")

Similar occurs for panel.xyplot

I find that ? xyplot  and ?panel. ... give the most uptodate methods things
change overtime.
There are some words on how information is passed to the key in ?xyplot
You either have to set trellis.par.set() or use the par.settings arguments

For older versions things may be slightly different.

If in a hurry I try the easiest but if that fails on the first go I just use
key = list(text = ... etc
 
Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard
Sent: Thursday, 20 October 2016 10:05
To: r-help@r-project.org
Subject: Re: [R] Lattice xyplot(): adding a legend

On Wed, 19 Oct 2016, Rich Shepard wrote:

>  I did read that but mis-applied what I read. Tried auto.key but that did
> not work as desired. Now I know to learn how to apply 'key'.

   Almost there after another careful reading Section 9.2.3 ff in the book.
Here's the command to produce the plot:

rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area
Precipitation",
 ylab = "Daily Total Amount (in)", xlab = "Date",
 scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
 y = list(at=c(min(rain$amount), max(rain$amount,
 pch = 20,
 col = c("black","red","dark green","dark blue","dark
goldenrod","purple"),
 key = simpleKey(text = levels(rain$station)[1:6],
   x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE))

   My question is how to pass pch = 20 to the key. simpleKey accepts only
the
logical TRUE as an argument and this produces a plot with filled circles for
the data but unfilled circles for the key. I find no example of specifying
pch for points in the key in either the book or ?xyplot, and I'm sure there
is a way of having the key symbols match both pch and color as the data
symbols.

   Is use of Rows() the solution?

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot(): adding a legend

2016-10-19 Thread Rich Shepard

On Wed, 19 Oct 2016, Rich Shepard wrote:


 I did read that but mis-applied what I read. Tried auto.key but that did
not work as desired. Now I know to learn how to apply 'key'.


  Almost there after another careful reading Section 9.2.3 ff in the book.
Here's the command to produce the plot:

rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area 
Precipitation",
ylab = "Daily Total Amount (in)", xlab = "Date",
scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
y = list(at=c(min(rain$amount), max(rain$amount,
pch = 20,
col = c("black","red","dark green","dark blue","dark goldenrod","purple"),
key = simpleKey(text = levels(rain$station)[1:6],
  x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE))

  My question is how to pass pch = 20 to the key. simpleKey accepts only the
logical TRUE as an argument and this produces a plot with filled circles for
the data but unfilled circles for the key. I find no example of specifying
pch for points in the key in either the book or ?xyplot, and I'm sure there
is a way of having the key symbols match both pch and color as the data
symbols.

  Is use of Rows() the solution?

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot(): adding a legend

2016-10-19 Thread Rich Shepard

On Wed, 19 Oct 2016, David Winsemius wrote:


The `legend` function is used with base graphics plotting (as is the par
function).


David,

  And that's how I used it before so it is the wrong template for this plot.
Mea culpa!


I think you might first read ?Lattice since it makes reference to the fact
that you can update trellis structures after they have been created.


  That's what I was trying to do but with the incorrect name.


The commands to add "legend" features to lattice plots are found under the
argument items with names "key". Search in ?xyplot for the strings
'legend' and 'key'. It would probably be easier to incorporate these in a
new plot call. There are several examples (well, four anyway) at the
?xyplot page. Since you mentioned having Sarkar's book, the place to look
for more examples is chapter 9 "Labels and Legends".


  I did read that but mis-applied what I read. Tried auto.key but that did
not work as desired. Now I know to learn how to apply 'key'.

Thanks,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Lattice xyplot(): adding a legend

2016-10-19 Thread David Winsemius

> On Oct 19, 2016, at 10:48 AM, Rich Shepard  wrote:
> 
>  After reading ?xyplot and pages 161-162 in Deepayan's book I'm still not
> getting the syntax correct to add a legend to a scatterplot. The data are
> attached as filename rain.dput.
> 
>  Without the legend (and testing interactively) the data plot but not the
> legend. Sourcing the script opens the display but neither data nor legend
> appear. I know that I'll need to adjust the legend's position so it fits in
> the empty space at the top, left center, but I need to see where it is
> first.
> 
>  I tried adding the legend to the xyplot() command with no difference in
> the results.
> 
>  In both cases R displays this error:
> 
> source("plot-rain-by-day.R")
> Error in as.graphicsAnnot(legend) (from plot-rain-by-day.R#16) :
>  argument "legend" is missing, with no default
> 
>  I've not found an example to follow so pointers to how to add the legend
> are needed.


> 
>  The script:
> 
> # This scatter plot has rain amounts by day for each station, distinguished 
> by color.
> 
> # load rain data file
> rain
> 
> # Create a factor from the date
> raindate <- as.factor(rain$date)
> 
> # Save original plotting parameters
> opar <- par(xpd=NA,no.readonly=T)
> 
> # Prepare the plot of the data
> rainbyday <- xyplot(rain$amount ~ raindate, main="Area Precipitation", 
> ylab="Daily Total Amount (in)", xlab="Date", 
> scales=list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot=90)), 
> pch=as.numeric(rain$station), col=c("black","red","dark green","dark 
> blue","dark goldenrod","dark goldenrod"))
> 
> # Add a legend
> legend(x=0.83, y=-1.65, pch=as.numeric(rainbyday), col=c("black","red","dark 
> green","dark blue","dark goldenrod","dark goldenrod"))


The `legend` function is used with base graphics plotting (as is the par 
function). I think you might first read ?Lattice since it makes reference to 
the fact that you can update trellis structures after they have been created.  
The commands to add "legend" features to lattice plots are found under the 
argument items with names "key". Search in ?xyplot for the strings 'legend' and 
'key'. It would probably be easier to incorporate these in a new plot call. 
There are several examples (well, four anyway)  at the ?xyplot page. Since you 
mentioned having Sarkar's book, the place to look for more examples is chapter 
9 "Labels and Legends".


> # Plot it
> plot(rainbyday)
> 
> # Reset display parameters
> par(opar)
> 
> TIA,
> 
> Rich__
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Lattice xyplot(): adding a legend

2016-10-19 Thread Rich Shepard

  After reading ?xyplot and pages 161-162 in Deepayan's book I'm still not
getting the syntax correct to add a legend to a scatterplot. The data are
attached as filename rain.dput.

  Without the legend (and testing interactively) the data plot but not the
legend. Sourcing the script opens the display but neither data nor legend
appear. I know that I'll need to adjust the legend's position so it fits in
the empty space at the top, left center, but I need to see where it is
first.

  I tried adding the legend to the xyplot() command with no difference in
the results.

  In both cases R displays this error:

source("plot-rain-by-day.R")
Error in as.graphicsAnnot(legend) (from plot-rain-by-day.R#16) :
  argument "legend" is missing, with no default

  I've not found an example to follow so pointers to how to add the legend
are needed.

  The script:

# This scatter plot has rain amounts by day for each station, distinguished by 
color.

# load rain data file
rain

# Create a factor from the date
raindate <- as.factor(rain$date)

# Save original plotting parameters
opar <- par(xpd=NA,no.readonly=T)

# Prepare the plot of the data
rainbyday <- xyplot(rain$amount ~ raindate, main="Area Precipitation", ylab="Daily Total Amount (in)", xlab="Date", 
scales=list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot=90)), pch=as.numeric(rain$station), col=c("black","red","dark green","dark 
blue","dark goldenrod","dark goldenrod"))

# Add a legend
legend(x=0.83, y=-1.65, pch=as.numeric(rainbyday), col=c("black","red","dark green","dark 
blue","dark goldenrod","dark goldenrod"))

# Plot it
plot(rainbyday)

# Reset display parameters
par(opar)

TIA,

Richstructure(list(station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("0.3E", 
"0.6W", "1.0WNW", "1.5N", "4.3WNW", "Airport"), class = "factor"), 
date = structure(c(16071, 16072, 16073, 16074, 16075, 16076, 
16077, 16078, 16079, 16080, 16081, 16082, 16083, 16084, 16085, 
16086, 16087, 16088, 16089, 16090, 16091, 16092, 16093, 16094, 
16095, 16096, 16097, 16098, 16099, 16100, 16101, 16040, 16041, 
16042, 16043, 16044, 16045, 16046, 16047, 16048, 16049, 16050, 
16051, 16052, 16053, 16054, 16055, 16056, 16057, 16058, 16059, 
16060, 16061, 16062, 16063, 16064, 16065, 16066, 16067, 16068, 
16069, 16070, 16071, 16072, 16073, 16074, 16075, 16076, 16077, 
16078, 16079, 16080, 16081, 16082, 16083, 16084, 16085, 16086, 
16087, 16088, 16089, 16090, 16091, 16092, 16093, 16094, 16095, 
16096, 16097, 16098, 16099, 16100, 16101, 16040, 16041, 16042, 
16043, 16044, 16045, 16046, 16047, 16048, 16049, 16050, 16051, 
16052, 16053, 16054, 16055, 16056, 16057, 16058, 16059, 16060, 
16061, 16062, 16063, 16064, 16065, 16066, 16067, 16068, 16069, 
16070, 16071, 16072, 16073, 16074, 16075, 16076, 16077, 16078, 
16079, 16080, 16081, 16082, 16083, 16084, 16085, 16086, 16087, 
16088, 16089, 16090, 16091, 16092, 16093, 16094, 16095, 16096, 
16097, 16098, 16099, 16100, 16101, 16040, 16041, 16042, 16043, 
16044, 16045, 16046, 16047, 16048, 16049, 16050, 16051, 16052, 
16053, 16054, 16055, 16056, 16057, 16058, 16059, 16060, 16061, 
16062, 16063, 16064, 16065, 16066, 16067, 16068, 16069, 16070, 
16071, 16072, 16073, 16074, 16075, 16076, 16077, 16078, 16079, 
16080, 16081, 16082, 16083, 16084, 16085, 16086, 16087, 16088, 
16089, 16090, 16091, 16092, 16093, 16094, 16095, 16096, 16097, 
16098, 16099, 16100, 16101, 16040, 16041, 16042, 16043, 16044, 
16045, 16046, 16047, 16048, 16049, 16050, 16051, 16052, 16053, 
16054, 16055, 16056, 16057, 16058, 16059, 16060, 16061,

Re: [R] [lattice::xyplot] Using (panel:.)abline with panel.superpose?

2015-10-07 Thread Duncan Mackay
Forgot to send to list

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Thursday, 8 October 2015 08:44
To: 'Szumiloski, John'
Subject: RE: [R] [lattice::xyplot] Using (panel:.)abline with
panel.superpose?

Hi John

I only got grid lines on your # code 2 with same lattice version on win 7
and blank for the first code

Try

xyplot(Y~X|Trt, data=dat,
   groups=Sbj,
   type='b',
   lty=1,
   cex=2,
   lwd=3,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   col=c('red', 'blue'),
   pch=c(16,17),
   panel= panel.superpose,
   panel.groups = function(x,y, ...){

panel.abline(h=ygrid, v=xgrid, col = gray(0.9) )

panel.xyplot(x,y, ...)

  }# panel
) # xyplot

It produces grid lines over the lines and points so one way around it is to
use alpha settings.
Not all devices will accept alpha.

xyplot(Y~X|Trt, data=dat,
   groups=Sbj,
   type='b',
   lty=1,
   cex=2,
   lwd=3,
   alpha = 1,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   col=c('red', 'blue'),
   pch=c(16,17),
   panel= panel.superpose,
   panel.groups = function(x,y,alpha, ...){

panel.abline(h=ygrid, v=xgrid, col=1, alpha = 0.1)

panel.xyplot(x,y, alpha = 1, ...)
   
  }# panel
) # xyplot

If you use par.settings it will give correct colours lines etc to auto key

xyplot(Y~X|Trt, data=dat,
   groups=Sbj,
   type='b',
   par.settings = list(strip.background = list(col = "transparent"),
   superpose.line = list(col = c('red', 'blue'),
 alpha = 1,
 lty=1,lwd=3),
   superpose.symbol = list(col=c('red', 'blue'),
   alpha = 1,
   pch=c(16,17),
   cex=2)),
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
 auto.key = T,
   panel= panel.superpose,
   panel.groups = function(x,y,alpha, ...){

panel.abline(h=ygrid, v = xgrid, col=1, alpha = 0.1)

panel.xyplot(x,y, alpha = 1, ...)

  }# panel
) # xyplot

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Szumiloski,
John
Sent: Thursday, 8 October 2015 03:40
To: r-help@r-project.org
Subject: [R] [lattice::xyplot] Using (panel:.)abline with panel.superpose?

Dear useRs,

I recently had a query concerning how to customize the graphics parameters
in lattice::xyplot to change not only the color but also the pch symbols,
lty and lwd line parameters, etc., within each grouping variable in the
plot.  (https://stat.ethz.ch/pipermail/r-help/2015-July/430285.html).  Many
thanks to Mark Leeds who described the solution using panel.superpose as the
panel function and defining a custom panel.groups function using the
subscripts argument.

Here is a crude example.  Note how the pch parameter varies with grouping
variable as well as color.  I have commented out two lines which are not
important for the example but are for my main question.

 begin code 1

# R version 3.2.2 release, lattice version 0.20-33, Windows 7.

dat <- data.frame(Trt=rep(c('1','2'), each=10),
  Sbj=rep(c('1','2'), each=5),
  X=rep(c(0,1,2,3,4), times=4),
  Y=c(1,3,3,3,1, 2,4,4,4,2,
  3,1,1,1,3, 4,2,2,2,4)
 )

xgrid <- seq(0L, 4L)
ygrid <- seq(0L, 5L)

require(lattice)
xyplot(Y ~ X | Trt, data=dat, groups=Sbj, type='b', lty=1, cex=2, lwd=3,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   ### abline=list(h=ygrid, v=xgrid, col=gray(0.8)),
   mycol=c('red', 'blue'), mypch=c(16,17),
   panel=panel.superpose,
   panel.groups=function(x, y, subscripts,
  mycol, mypch, col.line, col.symbol, pch,
...) {
 ### panel.abline(h=ygrid, v=xgrid,
col=gray(0.8))
 panel.xyplot(x, y, ...,
 pch =
mypch[dat[['Sbj']][subscripts]],
  col.symbol =
mycol[dat[['Sbj']][subscripts]],
col.line =

[R] [lattice::xyplot] Using (panel:.)abline with panel.superpose?

2015-10-07 Thread Szumiloski, John
Dear useRs,

I recently had a query concerning how to customize the graphics parameters in 
lattice::xyplot to change not only the color but also the pch symbols, lty and 
lwd line parameters, etc., within each grouping variable in the plot.  
(https://stat.ethz.ch/pipermail/r-help/2015-July/430285.html).  Many thanks to 
Mark Leeds who described the solution using panel.superpose as the panel 
function and defining a custom panel.groups function using the subscripts 
argument.

Here is a crude example.  Note how the pch parameter varies with grouping 
variable as well as color.  I have commented out two lines which are not 
important for the example but are for my main question.

 begin code 1

# R version 3.2.2 release, lattice version 0.20-33, Windows 7.

dat <- data.frame(Trt=rep(c('1','2'), each=10),
  Sbj=rep(c('1','2'), each=5),
  X=rep(c(0,1,2,3,4), times=4),
  Y=c(1,3,3,3,1, 2,4,4,4,2,
  3,1,1,1,3, 4,2,2,2,4)
 )

xgrid <- seq(0L, 4L)
ygrid <- seq(0L, 5L)

require(lattice)
xyplot(Y ~ X | Trt, data=dat, groups=Sbj, type='b', lty=1, cex=2, lwd=3,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   ### abline=list(h=ygrid, v=xgrid, col=gray(0.8)),
   mycol=c('red', 'blue'), mypch=c(16,17),
   panel=panel.superpose,
   panel.groups=function(x, y, subscripts,
  mycol, mypch, col.line, col.symbol, pch, ...) 
{
 ### panel.abline(h=ygrid, v=xgrid, 
col=gray(0.8))
 panel.xyplot(x, y, ...,
 pch = 
mypch[dat[['Sbj']][subscripts]],
  col.symbol = 
mycol[dat[['Sbj']][subscripts]],
col.line = 
mycol[dat[['Sbj']][subscripts]]
 )
} # function
  ) # xyplot

### end code 1

My question involves the commented out lines.  I would like to draw a light 
grid in the panels.  If I used panel.grid() it would be impossible to get the 
gridlines into arbitrary positions, as it seems to pick values similar to 
pretty() (I would love to be corrected on this).  So we can use an abline 
argument to the main xyplot call, or a panel.abline() call in the panel.groups 
function.

But either way leads to a problem.  The ablines seem to be rerendered for each 
level of the grouping variable, thus only the final level is plotted without 
being the grid rendered on top of it.  Try it by uncommenting either line.

This is not totally surprising as it does mention somewhere in the 
documentation that panel.groups() is called for each value of the grouping 
variable.  So my question: How do I render the grid just once, before actually 
rendering the data, so as to avoid this problem?

I realized a good place to start might be to include panel.abline in the panel 
function itself, rather in the panel.groups function called several times per 
panel.  Thus something like this:

### begin code 2

xyplot(Y~X|Trt, data=dat, groups=Sbj, type='b', lty=1, cex=2, lwd=3,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   mycol=c('red', 'blue'), mypch=c(16,17),
   panel=function(x, y, ...) {   ##  < new 
panel function
  panel.abline(h=ygrid, v=xgrid, col=gray(0.9))
  panel.superpose(x, y, ...)
 },
   panel.groups=function(x, y, subscripts,
  mycol, mypch, col.line, col.symbol, pch, ...) 
{
 panel.xyplot(x, y, ...,
 pch = 
mypch[dat[['Sbj']][subscripts]],
  col.symbol = 
mycol[dat[['Sbj']][subscripts]],
col.line = 
mycol[dat[['Sbj']][subscripts]]
 )
} # function
  ) # xyplot

### end code 2

Of course this won't work as written, I need to replace the ... arguments with 
the right ones.  Here is where I am having trouble.  I have tried all kinds of 
permutations of the mycol etc., xgrid etc., subscripts etc., and never got the 
plot to render the ablines once, then the data correctly.

Any assistance greatly appreciated.
John
John Szumiloski, Ph.D.
Principal Scientist, Statistician
Analytical and Bioanalytical Development
NBR105-1-1411

Bristol-Myers Squibb
P.O. Box 191
1 Squibb Drive
New Brunswick, NJ
08903-0191
USA

(732) 227-7167




 This message (including any attachments) may contain co...{{dropped:8}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more,

[R] lattice -xyplot

2014-07-22 Thread Katharina Mersmann
Dear Community,

Just a short and simple question, but the code does not come to my mind. 

I want to plot the Resids by quarterly Data. But there are many quarters. 

Just rotate them, does not make the plot clearer/ easier to read.

Is there a possibility to just show every 4th value on the x-axis ? How do I
change the scale?

 

require(lattice)

xyplot(resid(fixed.reg1.1) ~ quartal,type="h", data=data.plm,scales = list(x
= list(rot = 90))  ,ylim=c(-5,5))

 

 

Thanks a lot!

And have a nice day.

Katie


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-18 Thread Rich Shepard

On Fri, 18 Oct 2013, S Ellison wrote:


Using trellis.par.set seems more successful than specifying par.settings
in the call, however much I'd prefer to avoid relying on globals. Example:

ss<-trellis.par.get("superpose.symbol")
ss$pch=rep(19,7)
ss$col=rainbow(7)
trellis.par.set(superpose.symbol=ss)

#Example from xyplot
dotplot(variety ~ yield | site, data = barley, groups = year,
key = simpleKey(levels(barley$year), space = "right"),
xlab = "Barley Yield (bushels/acre) ",
aspect=0.5, layout = c(1,6), ylab=NULL)


  Thank you.

Rich

--
Richard B. Shepard, Ph.D.  |  Have knowledge, will travel.
Applied Ecosystem Services, Inc.   |
 Voice: 503-667-4517  Fax: 503-667-8863

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-18 Thread S Ellison


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Rich Shepard
> Subject: [R] Lattice xyplot: Fill Legend Points
> 
>When I specify pch = 19 for a scatter plot the points are filled
> circles.
> Deapite reading ?points and trial-and-error experimentation I have not
> found
> how to have the legend symbols (now open circles) filled.
> 

Using trellis.par.set seems more successful than specifying par.settings in the 
call, however much I'd prefer to avoid relying on globals. Example:

ss<-trellis.par.get("superpose.symbol")
ss$pch=rep(19,7)
ss$col=rainbow(7)
trellis.par.set(superpose.symbol=ss)

#Example from xyplot
dotplot(variety ~ yield | site, data = barley, groups = year,
 key = simpleKey(levels(barley$year), space = "right"),
 xlab = "Barley Yield (bushels/acre) ",
 aspect=0.5, layout = c(1,6), ylab=NULL)


S Ellison



***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Rich Shepard

On Thu, 17 Oct 2013, Richard M. Heiberger wrote:


I always get lost in simpleKey.


  As this is my first use of it I take what's offered by those more
experienced than I.


The approach of directly modifying the trellis object usually works.
tmp <- xyplot(pct.quant ~ sampdate, data = ffg.st, groups = func_feed_grp, type 
=
+ 'p', pch = 19, key = simpleKey(text = levels(ffg.st$func_feed_grp), space =
+ 'right', points = T, lines = F),par.settings = list(superpose.points =
+ list(col = rainbow(7)), superpose.lines = list(col = rainbow(7))), main =
+ 'Functional Feeding Groups (Individuals)', xlab = 'Year', ylab = 'Proportion
+ of Individuals')

tmp
str(tmp)
tmp$legend$right$args$key$points$pch

[1] 1 1 1 1 1 1 1

tmp$legend$right$args$key$points$pch[] <- 19
tmp$legend$right$args$key$points$pch

[1] 19 19 19 19 19 19 19


  OK. More steps but it will get the plots where they need to be.

Many thanks,

Rich

--
Richard B. Shepard, Ph.D.  |  Have knowledge, will travel.
Applied Ecosystem Services, Inc.   |
 Voice: 503-667-4517  Fax: 503-667-8863

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Richard M. Heiberger
I always get lost in simpleKey.  The approach of directly modifying
the trellis object usually works.

> tmp <- xyplot(pct.quant ~ sampdate, data = ffg.st, groups = func_feed_grp, 
> type =
+ 'p', pch = 19, key = simpleKey(text = levels(ffg.st$func_feed_grp), space =
+ 'right', points = T, lines = F),par.settings = list(superpose.points =
+ list(col = rainbow(7)), superpose.lines = list(col = rainbow(7))), main =
+ 'Functional Feeding Groups (Individuals)', xlab = 'Year', ylab = 'Proportion
+ of Individuals')
> tmp
> str(tmp)
> tmp$legend$right$args$key$points$pch
[1] 1 1 1 1 1 1 1
> tmp$legend$right$args$key$points$pch[] <- 19
> tmp$legend$right$args$key$points$pch
[1] 19 19 19 19 19 19 19
> tmp
>

Rich

On Thu, Oct 17, 2013 at 12:57 PM, Rich Shepard  wrote:
> On Thu, 17 Oct 2013, Richard M. Heiberger wrote:
>
>> That should have worked.
>
>
>   That's what I thought when I first tried it.
>
>
>> I think something else is interfering. Did you redefine either T or F?
>
>
>   Not intentionally.
>
>
>> Please send the output from dput(head(ffg.st)) so we can experiment in
>> your setting.
>
>
> structure(list(sampdate = structure(c(13326, 13326, 13326, 13326, 13326,
> 13326), class = "Date"), func_feed_grp = structure(c(1L, 2L, 3L, 4L, 6L,
> 7L), .Label = c("Filterer", "Gatherer", "Grazer", "Omnivore", "Parasite",
> "Predator", "Shredder"), class = "factor"),
> quant = c(812L, 1880L, 624L, 11L, 948L, 1540L), pct.quant = c(0.14,
> 0.323, 0.107, 0.002, 0.163, 0.265), num.taxa = c(11L, 28L,
> 4L, 1L, 12L, 3L), pct.num.taxa = c(0.186, 0.475, 0.068, 0.017,
> 0.203, 0.051)), .Names = c("sampdate", "func_feed_grp", "quant",
> "pct.quant", "num.taxa", "pct.num.taxa"), row.names = 102:107, class =
> "data.frame")
>
>
> Rich
>
> --
> Richard B. Shepard, Ph.D.  |  Have knowledge, will travel.
> Applied Ecosystem Services, Inc.   |
>  Voice: 503-667-4517  Fax: 503-667-8863
>
> __
> R-help@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.

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Rich Shepard

On Thu, 17 Oct 2013, Richard M. Heiberger wrote:


That should have worked.


  That's what I thought when I first tried it.


I think something else is interfering. Did you redefine either T or F?


  Not intentionally.


Please send the output from dput(head(ffg.st)) so we can experiment in
your setting.


structure(list(sampdate = structure(c(13326, 13326, 13326, 13326, 
13326, 13326), class = "Date"), func_feed_grp = structure(c(1L, 
2L, 3L, 4L, 6L, 7L), .Label = c("Filterer", "Gatherer", "Grazer", 
"Omnivore", "Parasite", "Predator", "Shredder"), class = "factor"),

quant = c(812L, 1880L, 624L, 11L, 948L, 1540L), pct.quant = c(0.14,
0.323, 0.107, 0.002, 0.163, 0.265), num.taxa = c(11L, 28L,
4L, 1L, 12L, 3L), pct.num.taxa = c(0.186, 0.475, 0.068, 0.017,
0.203, 0.051)), .Names = c("sampdate", "func_feed_grp", "quant", 
"pct.quant", "num.taxa", "pct.num.taxa"), row.names = 102:107, class =

"data.frame")

Rich

--
Richard B. Shepard, Ph.D.  |  Have knowledge, will travel.
Applied Ecosystem Services, Inc.   |
 Voice: 503-667-4517  Fax: 503-667-8863

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Richard M. Heiberger
That should have worked.  I think something else is interfering.
Did you redefine either T or F?

Please send the output from dput(head(ffg.st))
so we can experiment in your setting.

Rich

On Thu, Oct 17, 2013 at 12:12 PM, Rich Shepard  wrote:
> On Thu, 17 Oct 2013, Richard M. Heiberger wrote:
>
>> par.settings = list(
>>   superpose.points = list(col = rainbow(7), pch = 19),
>>   superpose.lines = list(col = rainbow(7))
>> )
>
>
>   I had tried that, too. Legend symbols stubbornly remain unfilled.
>
> Thanks, Richard,
>
> Rich
>
>
> __
> R-help@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.

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Rich Shepard

On Thu, 17 Oct 2013, Richard M. Heiberger wrote:


par.settings = list(
  superpose.points = list(col = rainbow(7), pch = 19),
  superpose.lines = list(col = rainbow(7))
)


  I had tried that, too. Legend symbols stubbornly remain unfilled.

Thanks, Richard,

Rich

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Richard M. Heiberger
par.settings = list(
   superpose.points = list(col = rainbow(7), pch = 19),
   superpose.lines = list(col = rainbow(7))
)

On Thu, Oct 17, 2013 at 11:48 AM, Rich Shepard  wrote:
> On Thu, 17 Oct 2013, Richard M. Heiberger wrote:
>
>> put the pch into the par.settings
>
>
> Richard,
>
>   Tried this again, but I'm not finding the proper location within
> par.settings.
>
>
> par.settings = list(superpose.points = list(col = rainbow(7)),
> superpose.lines = list(col = rainbow(7)), pch = 19)
>
>
> If I put it prior to the (list ... group there's an error of an extra = ;
> when I put it anywhere in the list (the above is one of my tries), it has no
> effect on the legend symbols: they remain as outlines.
>
>   What have I missed?
>
>
> Thanks,
>
> Rich
>
> --
> Richard B. Shepard, Ph.D.  |  Have knowledge, will travel.
> Applied Ecosystem Services, Inc.   |
>  Voice: 503-667-4517  Fax: 503-667-8863
>
> __
> R-help@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.

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Rich Shepard

On Thu, 17 Oct 2013, Richard M. Heiberger wrote:


put the pch into the par.settings


Richard,

  Tried this again, but I'm not finding the proper location within
par.settings.

par.settings = list(superpose.points = list(col = rainbow(7)),
superpose.lines = list(col = rainbow(7)), pch = 19)


If I put it prior to the (list ... group there's an error of an extra = ;
when I put it anywhere in the list (the above is one of my tries), it has no
effect on the legend symbols: they remain as outlines.

  What have I missed?

Thanks,

Rich

--
Richard B. Shepard, Ph.D.  |  Have knowledge, will travel.
Applied Ecosystem Services, Inc.   |
 Voice: 503-667-4517  Fax: 503-667-8863

__
R-help@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.


Re: [R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Richard M. Heiberger
put the pch into the par.settings

On Thu, Oct 17, 2013 at 11:17 AM, Rich Shepard  wrote:
>   When I specify pch = 19 for a scatter plot the points are filled circles.
> Deapite reading ?points and trial-and-error experimentation I have not found
> how to have the legend symbols (now open circles) filled.
>
>   An example command is:
>
> xyplot(pct.quant ~ sampdate, data = ffg.st, groups = func_feed_grp, type =
> 'p', pch = 19, key = simpleKey(text = levels(ffg.st$func_feed_grp), space =
> 'right', points = T, lines = F),par.settings = list(superpose.points =
> list(col = rainbow(7)), superpose.lines = list(col = rainbow(7))), main =
> 'Functional Feeding Groups (Individuals)', xlab = 'Year', ylab = 'Proportion
> of Individuals')
>
>   Please pass me a pointer on how to fill the legend points.
>
> TIA,
>
> Rich
>
> __
> R-help@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.

__
R-help@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.


[R] Lattice xyplot: Fill Legend Points

2013-10-17 Thread Rich Shepard

  When I specify pch = 19 for a scatter plot the points are filled circles.
Deapite reading ?points and trial-and-error experimentation I have not found
how to have the legend symbols (now open circles) filled.

  An example command is:

xyplot(pct.quant ~ sampdate, data = ffg.st, groups = func_feed_grp, type =
'p', pch = 19, key = simpleKey(text = levels(ffg.st$func_feed_grp), space =
'right', points = T, lines = F),par.settings = list(superpose.points =
list(col = rainbow(7)), superpose.lines = list(col = rainbow(7))), main =
'Functional Feeding Groups (Individuals)', xlab = 'Year', ylab = 'Proportion
of Individuals')

  Please pass me a pointer on how to fill the legend points.

TIA,

Rich

__
R-help@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.


Re: [R] Lattice xyplot multipanels

2013-05-22 Thread Santosh
Dear Rxperts..

Just figured how to add a text at a custom location in panel.groups..

use grid.text(x=unit(value1,"npc"),y=unit(value2,"npc"),label="label
content")

With this, I hope to stop flogging such a valuable black horse! :)



On Wed, May 22, 2013 at 10:35 AM, Santosh  wrote:

> Dear Rxperts,
> Using the above example, I have been playing around using viewport under
> "panel-function(...) {...}" block in conjunction with
> "panel.groups=function(..) {xyplot.}" code block.. I have not bee
> successful so far.. I was wondering if it is possible to pass user-defined
> functions (including data driven text annotations) in both "panel" and
> "panel.groups" arguments?
>
> Thanks so much..
> Santosh
>
>
> On Tue, May 21, 2013 at 10:04 PM, Santosh  wrote:
>
>> Dear Rxperts,
>> Sorry about that..forgot to update the numeric part of the multipanel
>> group indicator...
>>
>> Below is the updated code... in addition to getting rid of the curly
>> braces, is there a better way to control the position of
>> panel.text flexibly instead of hardcoding.
>>
>> Thanks,
>> santosh
>>
>> q <- data.frame(GL = rep(paste("G",1:3,sep = ""),each = 50),
>> G  = rep(1:3,each = 50),
>>  D = rep(paste("D",1:5,sep = ""),each = 30),
>> a = rep(1:15,each = 10),
>> t = rep(seq(10),15),
>>  b = round(runif(150,10,20)))
>>
>>  q$grp <- paste(q$D,q$a,sep = ":")
>> q$grp <- ordered(q$grp, levels = unique(q$grp))
>> q$dcol <- unlist(sapply(q$D,function(x) switch(x, "D1" = "orange",
>>  "D2" = "blue",
>> "D3" = "red",
>> "D4" = "seagreen",
>>  "D5" = "black")))
>> q2   <-  q[order(q$G,q$D,q$a,q$t),]
>> ref3 <-  subset(q2, !duplicated(a))
>> my.theme = list(strip.border = list(col = NA),
>> strip.background = list(col = NA)) # Of course, I can add a series of
>> "$".. I don't have too many "$"s!
>>
>> xyplot(b ~ t | G,data = q2,groups = grp,type = "l",as.table = T,
>> layout = c(3,1), par.strip.text = list(lines = 2),
>> panel = panel.superpose,
>> par.settings = my.theme,
>>  panel.groups = function(x = x,
>> y = y,
>> subscripts = subscripts,
>>  groups = groups,...,
>> group.number) {
>> require(grid)
>> panel.xyplot(x = x,y = y,
>>  subscripts = subscripts,pch = NA,lwd = 1,type = "l",
>> col = q2$dcol[subscripts],lty = 1,cex = 0.7)
>>  rv0<- ref3[ref3$G%in%unique(q2$G)[panel.number()],]
>>  panel.text(x=5,y=15,label=unique(rv0$GL))
>>  tids   <-  paste(as.character(unique(rv0$D)))
>> tcols   <-  unique(rv0$dcol)
>>  tlty<-  1
>> draw.key(list(columns = 1,between = 1,between.col = 0.5,
>> text = list(lab = tids,col = tcols,cex = 0.8),title =
>> "Classes",cex.title = 1.1
>>  ),
>> draw  =  T,vp  =  viewport(x  =  unit(0.8, "npc"), y  =
>>  unit(0.9, "npc")))
>>  },
>>  strip = strip.custom(strip.names = T,strip.levels = T,par.strip.text
>> = list(cex = 1.7,font = 2),bg = 0,var.name = "School"),
>> xlab = deparse(substitute(x)),
>> ylab = deparse(substitute(y)),
>> main = "Overlay of Profiles by Schools and Classes",
>> )
>>
>>
>>
>> On Tue, May 21, 2013 at 8:21 PM, David Winsemius 
>> wrote:
>>
>>>
>>> On May 21, 2013, at 5:07 PM, Santosh wrote:
>>>
>>> > Dear Rxperts,
>>> > Ok The "curly braces" as we talked before,...
>>> > They appear if the "group" argument of "xyplot" function is entered as
>>> a
>>> > numeric value; and don't when the values are letters.
>>>
>>> At the moment you are offering an example where the group argument is
>>> neither numeric, nor character, but rather is a factor-classed variable. I
>>> cannot make any curley items appear if I change the argument to numeric.
>>>
>>> On my machine (a Mac running R 3.0.0 RC) there are no curley braces ...
>>> on the strips (or anywhere else.)
>>>
>>> I do not know what you mean by "keep only side 1 and 2 of the borders".
>>> It is possible that you want to avoid alternating tick labels and need to
>>> find the switch to suppress ticks labels on the upper and right sides of
>>> the plotting borders. Try:
>>>
>>> ?xyplot  # scales section
>>>
>>> … scales=list(alternating=c(1,1,1) ),  # 1 choice repeated for the
>>> number of columns
>>>
>>> --
>>> David.
>>>
>>> > I just figured how to hide the strip borders...and also control the
>>> ticks
>>> > in different axes...
>>> >
>>> > Any suggestions to remove the *curly braces* are highly welcome.
>>> >
>>> >
>>> > q <- data.frame(G = rep(paste("G",1:3,sep = ""),each = 50),
>>> > D = rep(paste("D",1:5,sep = ""),each = 30),
>>> > a = rep(1:15,each = 10),
>>> > t = rep(seq(10),15),
>>> > b = round(runif(150,10,20)))
>>> > q$grp <- paste(q$D,q$a,sep = ":")
>>> > q$grp <- ordered(q$grp, levels = unique(q$grp))
>>> > q$dcol <- unlist(sapply(q$D,function(x) switch(x, "D1" = "orange",
>>> > "D2" = "blue",
>>> > "D3" = "red",
>>> > "D4" = "seagreen",
>>> > "D5" = "black")))
>>> > q2   <-  q[order(q$G,q$D,q$a,q$t),]
>>> > ref3 <-  subset(q2, !duplicated(a))
>>> > my.theme = list(strip.border = l

Re: [R] Lattice xyplot multipanels

2013-05-22 Thread Santosh
Dear Rxperts,
Using the above example, I have been playing around using viewport under
"panel-function(...) {...}" block in conjunction with
"panel.groups=function(..) {xyplot.}" code block.. I have not bee
successful so far.. I was wondering if it is possible to pass user-defined
functions (including data driven text annotations) in both "panel" and
"panel.groups" arguments?

Thanks so much..
Santosh


On Tue, May 21, 2013 at 10:04 PM, Santosh  wrote:

> Dear Rxperts,
> Sorry about that..forgot to update the numeric part of the multipanel
> group indicator...
>
> Below is the updated code... in addition to getting rid of the curly
> braces, is there a better way to control the position of
> panel.text flexibly instead of hardcoding.
>
> Thanks,
> santosh
>
> q <- data.frame(GL = rep(paste("G",1:3,sep = ""),each = 50),
> G  = rep(1:3,each = 50),
>  D = rep(paste("D",1:5,sep = ""),each = 30),
> a = rep(1:15,each = 10),
> t = rep(seq(10),15),
>  b = round(runif(150,10,20)))
>
>  q$grp <- paste(q$D,q$a,sep = ":")
> q$grp <- ordered(q$grp, levels = unique(q$grp))
> q$dcol <- unlist(sapply(q$D,function(x) switch(x, "D1" = "orange",
>  "D2" = "blue",
> "D3" = "red",
> "D4" = "seagreen",
>  "D5" = "black")))
> q2   <-  q[order(q$G,q$D,q$a,q$t),]
> ref3 <-  subset(q2, !duplicated(a))
> my.theme = list(strip.border = list(col = NA),
> strip.background = list(col = NA)) # Of course, I can add a series of
> "$".. I don't have too many "$"s!
>
> xyplot(b ~ t | G,data = q2,groups = grp,type = "l",as.table = T,
> layout = c(3,1), par.strip.text = list(lines = 2),
> panel = panel.superpose,
> par.settings = my.theme,
>  panel.groups = function(x = x,
> y = y,
> subscripts = subscripts,
>  groups = groups,...,
> group.number) {
> require(grid)
> panel.xyplot(x = x,y = y,
>  subscripts = subscripts,pch = NA,lwd = 1,type = "l",
> col = q2$dcol[subscripts],lty = 1,cex = 0.7)
>  rv0<- ref3[ref3$G%in%unique(q2$G)[panel.number()],]
>  panel.text(x=5,y=15,label=unique(rv0$GL))
>  tids   <-  paste(as.character(unique(rv0$D)))
> tcols   <-  unique(rv0$dcol)
> tlty<-  1
> draw.key(list(columns = 1,between = 1,between.col = 0.5,
> text = list(lab = tids,col = tcols,cex = 0.8),title =
> "Classes",cex.title = 1.1
>  ),
> draw  =  T,vp  =  viewport(x  =  unit(0.8, "npc"), y  =  unit(0.9,
> "npc")))
>  },
>  strip = strip.custom(strip.names = T,strip.levels = T,par.strip.text
> = list(cex = 1.7,font = 2),bg = 0,var.name = "School"),
> xlab = deparse(substitute(x)),
> ylab = deparse(substitute(y)),
> main = "Overlay of Profiles by Schools and Classes",
> )
>
>
>
> On Tue, May 21, 2013 at 8:21 PM, David Winsemius 
> wrote:
>
>>
>> On May 21, 2013, at 5:07 PM, Santosh wrote:
>>
>> > Dear Rxperts,
>> > Ok The "curly braces" as we talked before,...
>> > They appear if the "group" argument of "xyplot" function is entered as a
>> > numeric value; and don't when the values are letters.
>>
>> At the moment you are offering an example where the group argument is
>> neither numeric, nor character, but rather is a factor-classed variable. I
>> cannot make any curley items appear if I change the argument to numeric.
>>
>> On my machine (a Mac running R 3.0.0 RC) there are no curley braces ...
>> on the strips (or anywhere else.)
>>
>> I do not know what you mean by "keep only side 1 and 2 of the borders".
>> It is possible that you want to avoid alternating tick labels and need to
>> find the switch to suppress ticks labels on the upper and right sides of
>> the plotting borders. Try:
>>
>> ?xyplot  # scales section
>>
>> … scales=list(alternating=c(1,1,1) ),  # 1 choice repeated for the number
>> of columns
>>
>> --
>> David.
>>
>> > I just figured how to hide the strip borders...and also control the
>> ticks
>> > in different axes...
>> >
>> > Any suggestions to remove the *curly braces* are highly welcome.
>> >
>> >
>> > q <- data.frame(G = rep(paste("G",1:3,sep = ""),each = 50),
>> > D = rep(paste("D",1:5,sep = ""),each = 30),
>> > a = rep(1:15,each = 10),
>> > t = rep(seq(10),15),
>> > b = round(runif(150,10,20)))
>> > q$grp <- paste(q$D,q$a,sep = ":")
>> > q$grp <- ordered(q$grp, levels = unique(q$grp))
>> > q$dcol <- unlist(sapply(q$D,function(x) switch(x, "D1" = "orange",
>> > "D2" = "blue",
>> > "D3" = "red",
>> > "D4" = "seagreen",
>> > "D5" = "black")))
>> > q2   <-  q[order(q$G,q$D,q$a,q$t),]
>> > ref3 <-  subset(q2, !duplicated(a))
>> > my.theme = list(strip.border = list(col = NA),
>> > strip.background = list(col = NA)) # Of course, I can add a series of
>> "$"..
>> > I don't have too many "$"s!
>> >
>> > xyplot(b ~ t | G,data = q2,groups = grp,type = "l",as.table = T,
>> >layout = c(3,1), par.strip.text = list(lines = 2),
>> >panel = panel.superpose,
>> > par.settings = my.theme,
>> > panel.groups = function(x = x,
>> > y = y,
>> > subscripts = subscripts,
>> > groups = groups,...,
>>

Re: [R] Lattice xyplot multipanels

2013-05-21 Thread Santosh
Dear Rxperts,
Sorry about that..forgot to update the numeric part of the multipanel group
indicator...

Below is the updated code... in addition to getting rid of the curly
braces, is there a better way to control the position of
panel.text flexibly instead of hardcoding.

Thanks,
santosh

q <- data.frame(GL = rep(paste("G",1:3,sep = ""),each = 50),
G  = rep(1:3,each = 50),
D = rep(paste("D",1:5,sep = ""),each = 30),
a = rep(1:15,each = 10),
t = rep(seq(10),15),
b = round(runif(150,10,20)))

 q$grp <- paste(q$D,q$a,sep = ":")
q$grp <- ordered(q$grp, levels = unique(q$grp))
q$dcol <- unlist(sapply(q$D,function(x) switch(x, "D1" = "orange",
"D2" = "blue",
"D3" = "red",
"D4" = "seagreen",
"D5" = "black")))
q2   <-  q[order(q$G,q$D,q$a,q$t),]
ref3 <-  subset(q2, !duplicated(a))
my.theme = list(strip.border = list(col = NA),
strip.background = list(col = NA)) # Of course, I can add a series of "$"..
I don't have too many "$"s!

xyplot(b ~ t | G,data = q2,groups = grp,type = "l",as.table = T,
layout = c(3,1), par.strip.text = list(lines = 2),
panel = panel.superpose,
par.settings = my.theme,
panel.groups = function(x = x,
y = y,
subscripts = subscripts,
groups = groups,...,
group.number) {
require(grid)
panel.xyplot(x = x,y = y,
subscripts = subscripts,pch = NA,lwd = 1,type = "l",
col = q2$dcol[subscripts],lty = 1,cex = 0.7)
 rv0<- ref3[ref3$G%in%unique(q2$G)[panel.number()],]
 panel.text(x=5,y=15,label=unique(rv0$GL))
 tids   <-  paste(as.character(unique(rv0$D)))
tcols   <-  unique(rv0$dcol)
tlty<-  1
draw.key(list(columns = 1,between = 1,between.col = 0.5,
text = list(lab = tids,col = tcols,cex = 0.8),title =
"Classes",cex.title = 1.1
),
draw  =  T,vp  =  viewport(x  =  unit(0.8, "npc"), y  =  unit(0.9,
"npc")))
},
 strip = strip.custom(strip.names = T,strip.levels = T,par.strip.text =
list(cex = 1.7,font = 2),bg = 0,var.name = "School"),
xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)),
main = "Overlay of Profiles by Schools and Classes",
)



On Tue, May 21, 2013 at 8:21 PM, David Winsemius wrote:

>
> On May 21, 2013, at 5:07 PM, Santosh wrote:
>
> > Dear Rxperts,
> > Ok The "curly braces" as we talked before,...
> > They appear if the "group" argument of "xyplot" function is entered as a
> > numeric value; and don't when the values are letters.
>
> At the moment you are offering an example where the group argument is
> neither numeric, nor character, but rather is a factor-classed variable. I
> cannot make any curley items appear if I change the argument to numeric.
>
> On my machine (a Mac running R 3.0.0 RC) there are no curley braces ... on
> the strips (or anywhere else.)
>
> I do not know what you mean by "keep only side 1 and 2 of the borders". It
> is possible that you want to avoid alternating tick labels and need to find
> the switch to suppress ticks labels on the upper and right sides of the
> plotting borders. Try:
>
> ?xyplot  # scales section
>
> … scales=list(alternating=c(1,1,1) ),  # 1 choice repeated for the number
> of columns
>
> --
> David.
>
> > I just figured how to hide the strip borders...and also control the ticks
> > in different axes...
> >
> > Any suggestions to remove the *curly braces* are highly welcome.
> >
> >
> > q <- data.frame(G = rep(paste("G",1:3,sep = ""),each = 50),
> > D = rep(paste("D",1:5,sep = ""),each = 30),
> > a = rep(1:15,each = 10),
> > t = rep(seq(10),15),
> > b = round(runif(150,10,20)))
> > q$grp <- paste(q$D,q$a,sep = ":")
> > q$grp <- ordered(q$grp, levels = unique(q$grp))
> > q$dcol <- unlist(sapply(q$D,function(x) switch(x, "D1" = "orange",
> > "D2" = "blue",
> > "D3" = "red",
> > "D4" = "seagreen",
> > "D5" = "black")))
> > q2   <-  q[order(q$G,q$D,q$a,q$t),]
> > ref3 <-  subset(q2, !duplicated(a))
> > my.theme = list(strip.border = list(col = NA),
> > strip.background = list(col = NA)) # Of course, I can add a series of
> "$"..
> > I don't have too many "$"s!
> >
> > xyplot(b ~ t | G,data = q2,groups = grp,type = "l",as.table = T,
> >layout = c(3,1), par.strip.text = list(lines = 2),
> >panel = panel.superpose,
> > par.settings = my.theme,
> > panel.groups = function(x = x,
> > y = y,
> > subscripts = subscripts,
> > groups = groups,...,
> > group.number) {
> >require(grid)
> >panel.xyplot(x = x,y = y,
> > subscripts = subscripts,pch = NA,lwd = 1,type = "l",
> >col = q2$dcol[subscripts],lty = 1,cex = 0.7)
> > rv0<- ref3[ref3$G%in%unique(q2$G)[panel.number()],]
> > tids   <-  paste(as.character(unique(rv0$D)))
> >tcols   <-  unique(rv0$dcol)
> >tlty <-  1
> > draw.key(list(columns = 1,between = 1,between.col = 0.5,
> >text = list(lab = tids,col = tcols,cex = 0.8),title =
> > "Classes",cex.title = 1.1
> > ),
> >draw  =  T,vp  =  viewport(x  =  unit(0.8, "npc"), y  =  unit(0.9,
> > "npc")))

Re: [R] Lattice xyplot multipanels

2013-05-21 Thread Santosh
Dear Rxperts,
Ok The "curly braces" as we talked before,...
They appear if the "group" argument of "xyplot" function is entered as a
numeric value; and don't when the values are letters.
I just figured how to hide the strip borders...and also control the ticks
in different axes...

Any suggestions to remove the *curly braces* are highly welcome.


q <- data.frame(G = rep(paste("G",1:3,sep = ""),each = 50),
D = rep(paste("D",1:5,sep = ""),each = 30),
a = rep(1:15,each = 10),
t = rep(seq(10),15),
b = round(runif(150,10,20)))
q$grp <- paste(q$D,q$a,sep = ":")
q$grp <- ordered(q$grp, levels = unique(q$grp))
q$dcol <- unlist(sapply(q$D,function(x) switch(x, "D1" = "orange",
"D2" = "blue",
"D3" = "red",
"D4" = "seagreen",
"D5" = "black")))
q2   <-  q[order(q$G,q$D,q$a,q$t),]
ref3 <-  subset(q2, !duplicated(a))
my.theme = list(strip.border = list(col = NA),
strip.background = list(col = NA)) # Of course, I can add a series of "$"..
I don't have too many "$"s!

xyplot(b ~ t | G,data = q2,groups = grp,type = "l",as.table = T,
layout = c(3,1), par.strip.text = list(lines = 2),
panel = panel.superpose,
par.settings = my.theme,
panel.groups = function(x = x,
y = y,
subscripts = subscripts,
groups = groups,...,
group.number) {
require(grid)
panel.xyplot(x = x,y = y,
subscripts = subscripts,pch = NA,lwd = 1,type = "l",
col = q2$dcol[subscripts],lty = 1,cex = 0.7)
 rv0<- ref3[ref3$G%in%unique(q2$G)[panel.number()],]
 tids   <-  paste(as.character(unique(rv0$D)))
tcols   <-  unique(rv0$dcol)
tlty <-  1
draw.key(list(columns = 1,between = 1,between.col = 0.5,
text = list(lab = tids,col = tcols,cex = 0.8),title =
"Classes",cex.title = 1.1
),
draw  =  T,vp  =  viewport(x  =  unit(0.8, "npc"), y  =  unit(0.9,
"npc")))
},
 strip = strip.custom(strip.names = T,strip.levels = T,par.strip.text =
list(cex = 1.7,font = 2),bg = 0,var.name = "School"),
xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)),
main = "Overlay of Profiles by Schools and Classes",
)


On Tue, May 21, 2013 at 3:00 PM, Santosh  wrote:

> Dear Rxperts,
>
> Using the same example above, is there a way to remove the borders of
> multi-panel strips and control the display of the  borders of each panel..
> for example, I would like to keep only side 1 & 2 of a panel...
>
> Thanks,
> Santosh
>
>
>
>
> On Wed, May 1, 2013 at 11:11 PM, Santosh  wrote:
>
>> Thanks for all tips/suggestions..  Just a few more comments..
>> The same code I use with a different data set in another project does not
>> create those curly braces!
>>
>> Regards,
>> Santosh
>>
>>
>> On Wed, May 1, 2013 at 8:16 PM, Santosh  wrote:
>>
>>> Sorry about the word "brackets".. Yes, I meant curly  braces! I have not
>>> heard of "curley braces"! :).  Curly braces surrounding the values of
>>> "strip.levels" appear on the strip of multipanel plots.
>>>
>>> Thanks,
>>> Santosh
>>>
>>>
>>> On Wed, May 1, 2013 at 7:44 PM, David Winsemius 
>>> wrote:
>>>

 On May 1, 2013, at 6:16 PM, Santosh wrote:

 > Dear Rxperts,

 > I have a strange situation.. I see curly brackets

 Wait right here. What do you mean by "brackets"? In some locales, such
 as mine,  that might mean "[" ; in other domains... well,  who knows? I
 don't see any "[".

 The Urban Legends Newsgroup used to have a saying: TWIAVBP,  which is
 an initialism for: The World Is A Very Big Place. Pleas realize that
 language is local.

 > around "strip.levels" in
 > multipanel strips while using lattice::xyplot. .How do I get rid of
 the
 > curly brackets?

 Curly "brackets"? You mean curley braces? I see some of them in the
 code, but why in the world would one want to remove valid curley-braces in
 code? They just function as delimiters.


 > For some reason, I am not able to reproduce the problem
 > using an example below...

 What problem?  .. are you unable to reproduce? The code runs without
 error on my machine.


 > Any suggestions are highly welcome!
 > Thanks,
 > Santosh
 >
 > q <-
 >
 data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
 > q$grp <- paste(q$D,q$a,sep=":")
 > q$grp <-  ordered(q$grp, levels=unique(q$grp))
 > q$dcol  <- unlist(sapply(q$D,function(x)
 >switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
 > "D5"="black")))
 > q2 <- q[order(q$G,q$D,q$a,q$t),]
 > ref3 <- subset(q2, !duplicated(a))
 > xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
 >layout=c(3,1), par.strip.text = list(lines = 2),
 >panel=panel.superpose,
 >
 panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
 > {
 >require(grid)
 >
>

Re: [R] Lattice xyplot multipanels

2013-05-21 Thread Santosh
Dear Rxperts,

Using the same example above, is there a way to remove the borders of
multi-panel strips and control the display of the  borders of each panel..
for example, I would like to keep only side 1 & 2 of a panel...

Thanks,
Santosh




On Wed, May 1, 2013 at 11:11 PM, Santosh  wrote:

> Thanks for all tips/suggestions..  Just a few more comments..
> The same code I use with a different data set in another project does not
> create those curly braces!
>
> Regards,
> Santosh
>
>
> On Wed, May 1, 2013 at 8:16 PM, Santosh  wrote:
>
>> Sorry about the word "brackets".. Yes, I meant curly  braces! I have not
>> heard of "curley braces"! :).  Curly braces surrounding the values of
>> "strip.levels" appear on the strip of multipanel plots.
>>
>> Thanks,
>> Santosh
>>
>>
>> On Wed, May 1, 2013 at 7:44 PM, David Winsemius 
>> wrote:
>>
>>>
>>> On May 1, 2013, at 6:16 PM, Santosh wrote:
>>>
>>> > Dear Rxperts,
>>>
>>> > I have a strange situation.. I see curly brackets
>>>
>>> Wait right here. What do you mean by "brackets"? In some locales, such
>>> as mine,  that might mean "[" ; in other domains... well,  who knows? I
>>> don't see any "[".
>>>
>>> The Urban Legends Newsgroup used to have a saying: TWIAVBP,  which is an
>>> initialism for: The World Is A Very Big Place. Pleas realize that language
>>> is local.
>>>
>>> > around "strip.levels" in
>>> > multipanel strips while using lattice::xyplot. .How do I get rid of the
>>> > curly brackets?
>>>
>>> Curly "brackets"? You mean curley braces? I see some of them in the
>>> code, but why in the world would one want to remove valid curley-braces in
>>> code? They just function as delimiters.
>>>
>>>
>>> > For some reason, I am not able to reproduce the problem
>>> > using an example below...
>>>
>>> What problem?  .. are you unable to reproduce? The code runs without
>>> error on my machine.
>>>
>>>
>>> > Any suggestions are highly welcome!
>>> > Thanks,
>>> > Santosh
>>> >
>>> > q <-
>>> >
>>> data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
>>> > q$grp <- paste(q$D,q$a,sep=":")
>>> > q$grp <-  ordered(q$grp, levels=unique(q$grp))
>>> > q$dcol  <- unlist(sapply(q$D,function(x)
>>> >switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
>>> > "D5"="black")))
>>> > q2 <- q[order(q$G,q$D,q$a,q$t),]
>>> > ref3 <- subset(q2, !duplicated(a))
>>> > xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
>>> >layout=c(3,1), par.strip.text = list(lines = 2),
>>> >panel=panel.superpose,
>>> >
>>> panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
>>> > {
>>> >require(grid)
>>> >
>>>  panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
>>> >col=q2$dcol[subscripts],lty=1,cex=0.7)
>>> > rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
>>> > tids<- paste(as.character(unique(rv0$D)))
>>> >tcols   <- unique(rv0$dcol)
>>> >tlty<- 1
>>> > draw.key(list(columns=1,between=1,between.col=0.5,
>>> >
>>> > text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1
>>> > ),
>>> >draw = T,vp = viewport(x = unit(0.8, "npc"), y = unit(0.9,
>>> "npc")))
>>> >},
>>> >
>>> >
>>> strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,
>>> > var.name="School"),
>>> >xlab=deparse(substitute(x)),
>>> >ylab=deparse(substitute(y)),
>>> >main="Overlay of Profiles by Schools and Classes",
>>> > )
>>> >
>>>
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Lattice xyplot multipanels

2013-05-01 Thread Santosh
Thanks for all tips/suggestions..  Just a few more comments..
The same code I use with a different data set in another project does not
create those curly braces!

Regards,
Santosh


On Wed, May 1, 2013 at 8:16 PM, Santosh  wrote:

> Sorry about the word "brackets".. Yes, I meant curly  braces! I have not
> heard of "curley braces"! :).  Curly braces surrounding the values of
> "strip.levels" appear on the strip of multipanel plots.
>
> Thanks,
> Santosh
>
>
> On Wed, May 1, 2013 at 7:44 PM, David Winsemius wrote:
>
>>
>> On May 1, 2013, at 6:16 PM, Santosh wrote:
>>
>> > Dear Rxperts,
>>
>> > I have a strange situation.. I see curly brackets
>>
>> Wait right here. What do you mean by "brackets"? In some locales, such as
>> mine,  that might mean "[" ; in other domains... well,  who knows? I don't
>> see any "[".
>>
>> The Urban Legends Newsgroup used to have a saying: TWIAVBP,  which is an
>> initialism for: The World Is A Very Big Place. Pleas realize that language
>> is local.
>>
>> > around "strip.levels" in
>> > multipanel strips while using lattice::xyplot. .How do I get rid of the
>> > curly brackets?
>>
>> Curly "brackets"? You mean curley braces? I see some of them in the code,
>> but why in the world would one want to remove valid curley-braces in code?
>> They just function as delimiters.
>>
>>
>> > For some reason, I am not able to reproduce the problem
>> > using an example below...
>>
>> What problem?  .. are you unable to reproduce? The code runs without
>> error on my machine.
>>
>>
>> > Any suggestions are highly welcome!
>> > Thanks,
>> > Santosh
>> >
>> > q <-
>> >
>> data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
>> > q$grp <- paste(q$D,q$a,sep=":")
>> > q$grp <-  ordered(q$grp, levels=unique(q$grp))
>> > q$dcol  <- unlist(sapply(q$D,function(x)
>> >switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
>> > "D5"="black")))
>> > q2 <- q[order(q$G,q$D,q$a,q$t),]
>> > ref3 <- subset(q2, !duplicated(a))
>> > xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
>> >layout=c(3,1), par.strip.text = list(lines = 2),
>> >panel=panel.superpose,
>> >
>> panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
>> > {
>> >require(grid)
>> >panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
>> >col=q2$dcol[subscripts],lty=1,cex=0.7)
>> > rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
>> > tids<- paste(as.character(unique(rv0$D)))
>> >tcols   <- unique(rv0$dcol)
>> >tlty<- 1
>> > draw.key(list(columns=1,between=1,between.col=0.5,
>> >
>> > text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1
>> > ),
>> >draw = T,vp = viewport(x = unit(0.8, "npc"), y = unit(0.9,
>> "npc")))
>> >},
>> >
>> >
>> strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,
>> > var.name="School"),
>> >xlab=deparse(substitute(x)),
>> >ylab=deparse(substitute(y)),
>> >main="Overlay of Profiles by Schools and Classes",
>> > )
>> >
>>
>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Lattice xyplot multipanels

2013-05-01 Thread Duncan Mackay

Hi Santosh

Try this :

q <-
data.frame(G=rep(paste("G",1:3,sep=""),each=50),
   D=rep(paste("D",1:5,sep=""),each=30),
   a=rep(1:15,each=10),t=rep(seq(10),15),
   b=round(runif(150,10,20)))
q$grp <- paste(q$D,q$a,sep=":")
q$grp <-  ordered(q$grp, levels=unique(q$grp))
q$dcol <-
unlist(sapply(q$D,function(x)
switch(x,"D1"="orange","D2"="blue","D3"="red", 
"D4"="seagreen", "D5"="black")))

q2 <- q[order(q$G,q$D,q$a,q$t),]
ref3 <- subset(q2, !duplicated(a))

xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
   layout=c(3,1), par.strip.text = list(lines = 2),
   panel=panel.superpose,
   
strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,var.name="School"),
xlab=deparse(substitute(x)),
ylab=deparse(substitute(y)),
main="Overlay of Profiles by Schools and Classes",
   
panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number){

require(grid)
panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
 col=q2$dcol[subscripts],lty=1,cex=0.7)

rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
tids<- paste(as.character(unique(rv0$D)))
tcols   <- unique(rv0$dcol)
tlty<- 1

draw.key(list(columns=1,between=1,between.col=0.5,
  
text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1),
  draw = T,vp = viewport(x = unit(0.8, "npc"), y 
= unit(0.9, "npc")))

}
)

It works for me OK so I do not know what you mean. Version information below
I just rearranged your script - there was an extra "," at the end 
before the last ")"


R version 3.0.0 (2013-04-03), i386-w64-mingw32
 Base packages: base, datasets, graphics, grDevices, grid, methods, 
splines, stats, stats4, utils
 Other packages: chron 2.3-43, foreign 0.8-53, lattice 0.20-15, 
latticeExtra 0.6-24, MASS 7.3-26,

R.methodsS3 1.4.2, R.oo 1.13.0, RColorBrewer 1.0-5, VGAM 0.9-0, xtable 1.7-1

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

At 11:16 2/05/2013, you wrote:

Derar Rxperts,
I have a strange situation.. I see curly brackets around "strip.levels" in
multipanel strips while using lattice::xyplot. .How do I get rid of the
curly brackets? For some reason, I am not able to reproduce the problem
using an example below...
Any suggestions are highly welcome!
Thanks,
Santosh

q <-

data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
q$grp <- paste(q$D,q$a,sep=":")
q$grp <-  ordered(q$grp, levels=unique(q$grp))
q$dcol  <- unlist(sapply(q$D,function(x)
switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
"D5"="black")))
q2 <- q[order(q$G,q$D,q$a,q$t),]
ref3 <- subset(q2, !duplicated(a))
xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
layout=c(3,1), par.strip.text = list(lines = 2),
panel=panel.superpose,

panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
{
require(grid)
panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
col=q2$dcol[subscripts],lty=1,cex=0.7)
 rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
 tids<- paste(as.character(unique(rv0$D)))
tcols   <- unique(rv0$dcol)
tlty<- 1
draw.key(list(columns=1,between=1,between.col=0.5,

 text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1
),
draw = T,vp = viewport(x = unit(0.8, "npc"), y = unit(0.9, "npc")))
},


strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,
var.name="School"),
xlab=deparse(substitute(x)),
ylab=deparse(substitute(y)),
main="Overlay of Profiles by Schools and Classes",
)

[[alternative HTML version deleted]]

__
R-help@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.


__
R-help@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.


Re: [R] Lattice xyplot multipanels

2013-05-01 Thread David Winsemius

On May 1, 2013, at 8:16 PM, Santosh wrote:

> Sorry about the word "brackets".. Yes, I meant curly  braces! I have not 
> heard of "curley braces"! :).  Curly braces surrounding the values of 
> "strip.levels" appear on the strip of multipanel plots.

Not in my running of your code.



> Thanks,
> Santosh
> 
> 
> On Wed, May 1, 2013 at 7:44 PM, David Winsemius  
> wrote:
> 
> On May 1, 2013, at 6:16 PM, Santosh wrote:
> 
> > Dear Rxperts,
> > I have a strange situation.. I see curly brackets
> 
> Wait right here. What do you mean by "brackets"? In some locales, such as 
> mine,  that might mean "[" ; in other domains... well,  who knows? I don't 
> see any "[".
> 
> The Urban Legends Newsgroup used to have a saying: TWIAVBP,  which is an 
> initialism for: The World Is A Very Big Place. Pleas realize that language is 
> local.
> 
> > around "strip.levels" in
> > multipanel strips while using lattice::xyplot. .How do I get rid of the
> > curly brackets?
> 
> Curly "brackets"? You mean curley braces? I see some of them in the code, but 
> why in the world would one want to remove valid curley-braces in code? They 
> just function as delimiters.
> 
> 
> > For some reason, I am not able to reproduce the problem
> > using an example below...
> 
> What problem?  .. are you unable to reproduce? The code runs without error on 
> my machine.
> 
> 
> > Any suggestions are highly welcome!
> > Thanks,
> > Santosh
> >
> > q <-
> > data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
> > q$grp <- paste(q$D,q$a,sep=":")
> > q$grp <-  ordered(q$grp, levels=unique(q$grp))
> > q$dcol  <- unlist(sapply(q$D,function(x)
> >switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
> > "D5"="black")))
> > q2 <- q[order(q$G,q$D,q$a,q$t),]
> > ref3 <- subset(q2, !duplicated(a))
> > xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
> >layout=c(3,1), par.strip.text = list(lines = 2),
> >panel=panel.superpose,
> > panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
> > {
> >require(grid)
> >panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
> >col=q2$dcol[subscripts],lty=1,cex=0.7)
> > rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
> > tids<- paste(as.character(unique(rv0$D)))
> >tcols   <- unique(rv0$dcol)
> >tlty<- 1
> > draw.key(list(columns=1,between=1,between.col=0.5,
> >
> > text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1
> > ),
> >draw = T,vp = viewport(x = unit(0.8, "npc"), y = unit(0.9, "npc")))
> >},
> >
> > strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,
> > var.name="School"),
> >xlab=deparse(substitute(x)),
> >ylab=deparse(substitute(y)),
> >main="Overlay of Profiles by Schools and Classes",
> > )
> >
> 

David Winsemius
Alameda, CA, USA

__
R-help@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.


Re: [R] Lattice xyplot multipanels

2013-05-01 Thread Santosh
Sorry about the word "brackets".. Yes, I meant curly  braces! I have not
heard of "curley braces"! :).  Curly braces surrounding the values of
"strip.levels" appear on the strip of multipanel plots.

Thanks,
Santosh


On Wed, May 1, 2013 at 7:44 PM, David Winsemius wrote:

>
> On May 1, 2013, at 6:16 PM, Santosh wrote:
>
> > Dear Rxperts,
> > I have a strange situation.. I see curly brackets
>
> Wait right here. What do you mean by "brackets"? In some locales, such as
> mine,  that might mean "[" ; in other domains... well,  who knows? I don't
> see any "[".
>
> The Urban Legends Newsgroup used to have a saying: TWIAVBP,  which is an
> initialism for: The World Is A Very Big Place. Pleas realize that language
> is local.
>
> > around "strip.levels" in
> > multipanel strips while using lattice::xyplot. .How do I get rid of the
> > curly brackets?
>
> Curly "brackets"? You mean curley braces? I see some of them in the code,
> but why in the world would one want to remove valid curley-braces in code?
> They just function as delimiters.
>
>
> > For some reason, I am not able to reproduce the problem
> > using an example below...
>
> What problem?  .. are you unable to reproduce? The code runs without error
> on my machine.
>
>
> > Any suggestions are highly welcome!
> > Thanks,
> > Santosh
> >
> > q <-
> >
> data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
> > q$grp <- paste(q$D,q$a,sep=":")
> > q$grp <-  ordered(q$grp, levels=unique(q$grp))
> > q$dcol  <- unlist(sapply(q$D,function(x)
> >switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
> > "D5"="black")))
> > q2 <- q[order(q$G,q$D,q$a,q$t),]
> > ref3 <- subset(q2, !duplicated(a))
> > xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
> >layout=c(3,1), par.strip.text = list(lines = 2),
> >panel=panel.superpose,
> >
> panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
> > {
> >require(grid)
> >panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
> >col=q2$dcol[subscripts],lty=1,cex=0.7)
> > rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
> > tids<- paste(as.character(unique(rv0$D)))
> >tcols   <- unique(rv0$dcol)
> >tlty<- 1
> > draw.key(list(columns=1,between=1,between.col=0.5,
> >
> > text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1
> > ),
> >draw = T,vp = viewport(x = unit(0.8, "npc"), y = unit(0.9,
> "npc")))
> >},
> >
> >
> strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,
> > var.name="School"),
> >xlab=deparse(substitute(x)),
> >ylab=deparse(substitute(y)),
> >main="Overlay of Profiles by Schools and Classes",
> > )
> >
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Lattice xyplot multipanels

2013-05-01 Thread David Winsemius

On May 1, 2013, at 6:16 PM, Santosh wrote:

> Derar Rxperts,
> I have a strange situation.. I see curly brackets

Wait right here. What do you mean by "brackets"? In some locales, such as mine, 
 that might mean "[" ; in other domains... well,  who knows? I don't see any 
"[".

The Urban Legends Newsgroup used to have a saying: TWIAVBP,  which is an 
initialism for: The World Is A Very Big Place. Pleas realize that language is 
local.

> around "strip.levels" in
> multipanel strips while using lattice::xyplot. .How do I get rid of the
> curly brackets?

Curly "brackets"? You mean curley braces? I see some of them in the code, but 
why in the world would one want to remove valid curley-braces in code? They 
just function as delimiters.


> For some reason, I am not able to reproduce the problem
> using an example below...

What problem?  .. are you unable to reproduce? The code runs without error on 
my machine.


> Any suggestions are highly welcome!
> Thanks,
> Santosh
> 
> q <-
> data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
> q$grp <- paste(q$D,q$a,sep=":")
> q$grp <-  ordered(q$grp, levels=unique(q$grp))
> q$dcol  <- unlist(sapply(q$D,function(x)
>switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
> "D5"="black")))
> q2 <- q[order(q$G,q$D,q$a,q$t),]
> ref3 <- subset(q2, !duplicated(a))
> xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
>layout=c(3,1), par.strip.text = list(lines = 2),
>panel=panel.superpose,
> panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
> {
>require(grid)
>panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
>col=q2$dcol[subscripts],lty=1,cex=0.7)
> rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
> tids<- paste(as.character(unique(rv0$D)))
>tcols   <- unique(rv0$dcol)
>tlty<- 1
> draw.key(list(columns=1,between=1,between.col=0.5,
> 
> text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1
> ),
>draw = T,vp = viewport(x = unit(0.8, "npc"), y = unit(0.9, "npc")))
>},
> 
> strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,
> var.name="School"),
>xlab=deparse(substitute(x)),
>ylab=deparse(substitute(y)),
>main="Overlay of Profiles by Schools and Classes",
> )
> 

Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.Please stop sending 
HTML.Please stop sending HTML.Please stop sending HTML.

>   [[alternative HTML version deleted]]
> 


And please explain what you want in language that transcends your own keyboard 
and mental constructs.

-- 


David Winsemius
Alameda, CA, USA

__
R-help@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.


[R] Lattice xyplot multipanels

2013-05-01 Thread Santosh
Derar Rxperts,
I have a strange situation.. I see curly brackets around "strip.levels" in
multipanel strips while using lattice::xyplot. .How do I get rid of the
curly brackets? For some reason, I am not able to reproduce the problem
using an example below...
Any suggestions are highly welcome!
Thanks,
Santosh

q <-
 
data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
q$grp <- paste(q$D,q$a,sep=":")
q$grp <-  ordered(q$grp, levels=unique(q$grp))
q$dcol  <- unlist(sapply(q$D,function(x)
switch(x,"D1"="orange","D2"="blue","D3"="red", "D4"="seagreen",
"D5"="black")))
q2 <- q[order(q$G,q$D,q$a,q$t),]
ref3 <- subset(q2, !duplicated(a))
xyplot(b~t|G,data=q2,groups=grp,type="l",as.table=T,
layout=c(3,1), par.strip.text = list(lines = 2),
panel=panel.superpose,
 
panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number)
{
require(grid)
panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type="l",
col=q2$dcol[subscripts],lty=1,cex=0.7)
 rv0 <-ref3[ref3$G%in%unique(q2$G)[panel.number()],]
 tids<- paste(as.character(unique(rv0$D)))
tcols   <- unique(rv0$dcol)
tlty<- 1
draw.key(list(columns=1,between=1,between.col=0.5,

 text=list(lab=tids,col=tcols,cex=0.8),title="Classes",cex.title=1.1
),
draw = T,vp = viewport(x = unit(0.8, "npc"), y = unit(0.9, "npc")))
},

 
strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0,
var.name="School"),
xlab=deparse(substitute(x)),
ylab=deparse(substitute(y)),
main="Overlay of Profiles by Schools and Classes",
)

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] lattice xyplot point labelling

2013-02-28 Thread maxbre
hi duncan, thanks a lot for your help!

yes, your solution is working fine with a little tweaking of the vector 
"poscec" : but on the other hand it's just affecting the relative 
position of labels around respective points;
to get more flexibility would be probably better to supply  (even if I 
do not know exactly how) a set of coordinates for respective labels via 
the parameters "x" and  "y" or maybe just changing the position of some 
specific labels remaing the rest unaltered
can you think to a viable solution for this approach?
I've been trying that but for reasons I do not fully understand I can't 
make it work

thanks again for your valuable help

Massimo Bressan

ARPAV
Environmental Protection Agency of Veneto Region - Italy
Department of Treviso
31100 Treviso, Italy




Il 27/02/2013 23:38, Duncan Mackay-2 [via R] ha scritto:
> hi
>
> the bottom panel seems ok so for the top you
> supply a vector of positions that are your
> required positions (name eg posvec) to the panel
> function. may need to do the same for other functions
> to access the correct panel there is the ifelse statement
>
> posvec = c(...)
>
>panel = function(x, y , subscripts,...) {
>pnl = panel.number()
>panel.xyplot(x, y, cex=0.8,...)
>panel.abline(a = 0, b = 1, lty = 2, col ="gray")
>if (pnl == 2){
>panel.text(x, y, labels=tv.ms$inq[subscripts],
>   cex = 0.7, pos=3, offset=1, srt=0, adj=c(1,1))
>} else {
>panel.text(x, y, labels=tv.ms$inq[subscripts],
>   cex = 0.7, pos=posvec, offset=1, srt=0, adj=c(1,1))
>}
>#alternative to the use of panel.text
>#ltext(x=x, y=y, labels=tv.ms$inq[subscripts], pos=1, cex=0.8)
>  },
>
> HTh
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: [hidden email] 
> 
>
>
> At 22:30 27/02/2013, you wrote:
>
> >This is my reproducible example
> >tv.ms<-structure(list(inq = structure(4:17,
> >.Label = c("D4", "D5", "D6a", "D6b", "D6c",
> >"D7", "D8", "F4", "F5a", "F5b", "F6a", "F6b",
> >"F6c", "F6d", "F7a", "F7b", "F8"), class =
> >"factor"), tv.km.median.iteq =
> >c(0.324, 0.238,
> >0.242, 0.0801,
> >0.985, 0.309,
> >4.470003, 0.625,
> >0.625, 0.18, 0.796,
> >0.32, 0.0205, 0.01),
> >ms.km.median.iteq = c(0.422,
> >0.381, 0.33, 0.0901,
> >1.069994, 0.5599974,
> >5.200027, 1.5, 1.19, 0.469,
> >0.312, 0.459,
> >0.0403, 0.04 ), type = c("PCDD",
> >"PCDD", "PCDD", "PCDD", "PCDF", "PCDF", "PCDF",
> >"PCDF", "PCDF", "PCDF", "PCDF", "PCDF", "PCDF",
> >"PCDF")), .Names = c("inq", "tv.km.median.iteq",
> >"ms.km.median.iteq", "type"), row.names = 4:17,
> >class = "data.frame") I worked out the chart
> >mainly with the hints of this great forum
> >(thanks again for that): what I’ve done so far
> >accomplishes my needs except for that now I need
> >a little final tweaking in order to avoid the
> >overlapping of some specific labels (i.e. by
> >looking at the plot the labels: F6b and F6a, F7a
> >and F5a)
> >xyplot(tv.km.median.iteq~ms.km.median.iteq|type,
> >data=tv.ms, layout=c(1,2),
> >aspect="xy", xlab = expression(paste('ms
> >[ fg/', m^3, ' ]', sep = '')), ylab =
> >expression(paste('tv [ fg/', m^3, ' ]', sep =
> >'')), scales= list(relation="free",
> >log=10, cex=0.8),prepanel =
> >function(x, y, subscripts) {   rr<-
> >range(cbind(x,y))   list(xlim = rr,
> >ylim= rr) }, panel = function(x,
> >y , subscripts,...) {   panel.xyplot(x,
> >y, cex=0.8,...)   panel.abline(a = 0, b
> >= 1, lty = 2, col
> >="gray")   panel.text(x, y,
> >labels=tv.ms$inq[subscripts],
> >cex = 0.7, pos=3, offset=1, srt=0,
> >adj=c(1,1))   #alternative to the use of
> >panel.text   #ltext(x=x, y=y,
> >labels=tv.ms$inq[subscripts], pos=1,
> >cex=0.8) }, #subscripts=TRUE,
> >  xscale.components =
> >function(...)  {   ans <-
> >xscale.components.logpower(...)   range
> ><- ans$num.limit   newtck <-
> >round(seq(range[1],range[2],l=7),1)
> >ans$bottom$ticks$at <-
> >newtck   ans$bottom$labels$at <-
> >newtck   ans$bottom$labels$labels
> ><-parse(text=paste('10^',newtck,sep=''))
> >ans } , yscale.components  =
> >function(...)  {   ans <-
> >yscale.components.logpower(...)   range
> ><- ans$num.limit   newtck <-
> >round(seq(range[1],range[2],l=7),1)
> >ans$left$ticks$at <-
> >newtck   ans$left$labels$at <-
> >newtck   ans$left$labels$labels
> ><-parse(text=paste('10^',newtck,sep=''))
> >ans } ) I’m thinking t

Re: [R] lattice xyplot point labelling

2013-02-27 Thread Duncan Mackay

hi

the bottom panel seems ok so for the top you 
supply a vector of positions that are your 
required positions (name eg posvec) to the panel 
function. may need to do the same for other functions

to access the correct panel there is the ifelse statement

posvec = c(...)

  panel = function(x, y , subscripts,...) {
  pnl = panel.number()
  panel.xyplot(x, y, cex=0.8,...)
  panel.abline(a = 0, b = 1, lty = 2, col ="gray")
  if (pnl == 2){
  panel.text(x, y, labels=tv.ms$inq[subscripts],
 cex = 0.7, pos=3, offset=1, srt=0, adj=c(1,1))
  } else {
  panel.text(x, y, labels=tv.ms$inq[subscripts],
 cex = 0.7, pos=posvec, offset=1, srt=0, adj=c(1,1))
  }
  #alternative to the use of panel.text
  #ltext(x=x, y=y, labels=tv.ms$inq[subscripts], pos=1, cex=0.8)
},

HTh

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


At 22:30 27/02/2013, you wrote:
This is my reproducible example 
tv.ms<-structure(list(inq = structure(4:17, 
.Label = c("D4", "D5", "D6a", "D6b", "D6c", 
"D7", "D8", "F4", "F5a", "F5b", "F6a", "F6b", 
"F6c", "F6d", "F7a", "F7b", "F8"), class = 
"factor"), tv.km.median.iteq = 
c(0.324, 0.238, 
0.242, 0.0801, 
0.985, 0.309, 
4.470003, 0.625, 
0.625, 0.18, 0.796, 
0.32, 0.0205, 0.01), 
ms.km.median.iteq = c(0.422, 
0.381, 0.33, 0.0901, 
1.069994, 0.5599974, 
5.200027, 1.5, 1.19, 0.469, 
0.312, 0.459, 
0.0403, 0.04 ), type = c("PCDD", 
"PCDD", "PCDD", "PCDD", "PCDF", "PCDF", "PCDF", 
"PCDF", "PCDF", "PCDF", "PCDF", "PCDF", "PCDF", 
"PCDF")), .Names = c("inq", "tv.km.median.iteq", 
"ms.km.median.iteq", "type"), row.names = 4:17, 
class = "data.frame") I worked out the chart 
mainly with the hints of this great forum 
(thanks again for that): what I’ve done so far 
accomplishes my needs except for that now I need 
a little final tweaking in order to avoid the 
overlapping of some specific labels (i.e. by 
looking at the plot the labels: F6b and F6a, F7a 
and F5a) 
xyplot(tv.km.median.iteq~ms.km.median.iteq|type, 
data=tv.ms, layout=c(1,2), 
aspect="xy", xlab = expression(paste('ms 
[ fg/', m^3, ' ]', sep = '')), ylab = 
expression(paste('tv [ fg/', m^3, ' ]', sep = 
'')), scales= list(relation="free", 
log=10, cex=0.8),prepanel = 
function(x, y, subscripts) {   rr<- 
range(cbind(x,y))   list(xlim = rr, 
ylim= rr) }, panel = function(x, 
y , subscripts,...) {   panel.xyplot(x, 
y, cex=0.8,...)   panel.abline(a = 0, b 
= 1, lty = 2, col 
="gray")   panel.text(x, y, 
labels=tv.ms$inq[subscripts], 
cex = 0.7, pos=3, offset=1, srt=0, 
adj=c(1,1))   #alternative to the use of 
panel.text   #ltext(x=x, y=y, 
labels=tv.ms$inq[subscripts], pos=1, 
cex=0.8) }, #subscripts=TRUE, 
 xscale.components = 
function(...)  {   ans <- 
xscale.components.logpower(...)   range 
<- ans$num.limit   newtck <- 
round(seq(range[1],range[2],l=7),1) 
ans$bottom$ticks$at <- 
newtck   ans$bottom$labels$at <- 
newtck   ans$bottom$labels$labels 
<-parse(text=paste('10^',newtck,sep='')) 
ans } , yscale.components  = 
function(...)  {   ans <- 
yscale.components.logpower(...)   range 
<- ans$num.limit   newtck <- 
round(seq(range[1],range[2],l=7),1) 
ans$left$ticks$at <- 
newtck   ans$left$labels$at <- 
newtck   ans$left$labels$labels 
<-parse(text=paste('10^',newtck,sep='')) 
ans } ) I’m thinking to sort out the 
problem by: 1 -   plotting all labels except 
for those overlapping (i.e the above mentioned 
points); 2 -  plotting the remaining labels 
(i.e. the overlapping ones) by introducing a 
“manual displacement”; I know that’s 
probably not much efficient nor elegant 
resorting to a “manual solution” involving 
at least two “plotting steps” (the first to 
see where to tweak and the second to fix) but I 
can’t think to any other solution Any help? 
Thank you max -- View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-point-labelling-tp4659798.html 
Sent from the R help mailing list archive at 
Nabble.com. 
__ 
R-help@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.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-he

[R] lattice xyplot point labelling

2013-02-27 Thread maxbre
This is my reproducible example

tv.ms<-structure(list(inq = structure(4:17, .Label = c("D4", "D5", "D6a", 
"D6b", "D6c", "D7", "D8", "F4", "F5a", "F5b", "F6a", "F6b", "F6c", 
"F6d", "F7a", "F7b", "F8"), class = "factor"), tv.km.median.iteq =
c(0.324, 
0.238, 0.242, 0.0801, 0.985, 
0.309, 4.470003, 0.625, 0.625, 
0.18, 0.796, 0.32, 0.0205, 0.01), ms.km.median.iteq
= c(0.422, 
0.381, 0.33, 0.0901, 1.069994, 
0.5599974, 5.200027, 1.5, 1.19, 0.469, 
0.312, 0.459, 0.0403, 0.04
), type = c("PCDD", "PCDD", "PCDD", "PCDD", "PCDF", "PCDF", "PCDF", 
"PCDF", "PCDF", "PCDF", "PCDF", "PCDF", "PCDF", "PCDF")), .Names = c("inq", 
"tv.km.median.iteq", "ms.km.median.iteq", "type"), row.names = 4:17, class =
"data.frame")


I worked out the chart mainly with the hints of this great forum (thanks
again for that): what I’ve done so far accomplishes my needs except for that
now I need a little final tweaking in order to avoid the overlapping of some
specific labels (i.e. by looking at the plot the labels: F6b and F6a, F7a
and F5a)


xyplot(tv.km.median.iteq~ms.km.median.iteq|type, data=tv.ms,
layout=c(1,2),
aspect="xy", 
xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), 
ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), 
scales= list(relation="free", log=10, cex=0.8), 

   prepanel = function(x, y, subscripts) { 
  rr<- range(cbind(x,y)) 
  list(xlim = rr, ylim= rr) 
}, 
panel = function(x, y , subscripts,...) { 
  panel.xyplot(x, y, cex=0.8,...) 
  panel.abline(a = 0, b = 1, lty = 2, col ="gray") 
  panel.text(x, y, labels=tv.ms$inq[subscripts], 
 cex = 0.7, pos=3, offset=1, srt=0, adj=c(1,1))
  #alternative to the use of panel.text
  #ltext(x=x, y=y, labels=tv.ms$inq[subscripts], pos=1, cex=0.8)
}, 
#subscripts=TRUE, 
xscale.components = function(...)  { 
  ans <- xscale.components.logpower(...) 
  range <- ans$num.limit 
  newtck <- round(seq(range[1],range[2],l=7),1) 
  ans$bottom$ticks$at <- newtck 
  ans$bottom$labels$at <- newtck 
  ans$bottom$labels$labels <-parse(text=paste('10^',newtck,sep='')) 
  ans 
} , 
yscale.components  = function(...)  { 
  ans <- yscale.components.logpower(...) 
  range <- ans$num.limit 
  newtck <- round(seq(range[1],range[2],l=7),1) 
  ans$left$ticks$at <- newtck 
  ans$left$labels$at <- newtck 
  ans$left$labels$labels <-parse(text=paste('10^',newtck,sep='')) 
  ans 
}
)

I’m thinking to sort out the problem by:
1 - plotting all labels except for those overlapping (i.e the above
mentioned points);
2 - plotting the remaining labels (i.e. the overlapping ones) by introducing
a “manual displacement”;

I know that’s probably not much efficient nor elegant resorting to a “manual
solution” involving at least two “plotting steps” (the first to see where to
tweak and the second to fix) but I can’t think to any other solution

Any help?

Thank you

max




--
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-point-labelling-tp4659798.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] lattice::xyplot & file output

2012-12-20 Thread Pascal Oettli

Hello,

A reproducible example would be nice.

Anyway, with "lattice::xyplot", you can store, then print the figure, in 
order to write it into a file:


> xyObj <- xyplot(...)
> postscript(...)
> print(xyObj)
> dev.off()

Regards,
Pascal

Le 21/12/2012 02:29, Sam Steingold a écrit :

Hi,
When I was using the regular plot() function, I added this:

--8<---cut here---start->8---
   if (!is.null(file)) {
 do.call(tools::file_ext(file),list(file = file))
 on.exit(dev.off())
 cat("writing",file,"\n")
   }
--8<---cut here---end--->8---

to the beginning of each of my functions which plotted anything.
now that I am using lattice::xyplot to plot multiple lines, the above
code does NOT result in the plot being written to a file.
why?

I trued passing file=file to xyplot but that appears to be ignored too.

so, how do I tell lattice::xyplot to write charts in png files?

thanks!




__
R-help@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.


Re: [R] lattice::xyplot & file output

2012-12-20 Thread Rolf Turner


See FAQ 7.22 and fortune("line 800").

cheers,

Rolf Turner

On 21/12/12 06:29, Sam Steingold wrote:

Hi,
When I was using the regular plot() function, I added this:

--8<---cut here---start->8---
   if (!is.null(file)) {
 do.call(tools::file_ext(file),list(file = file))
 on.exit(dev.off())
 cat("writing",file,"\n")
   }
--8<---cut here---end--->8---

to the beginning of each of my functions which plotted anything.
now that I am using lattice::xyplot to plot multiple lines, the above
code does NOT result in the plot being written to a file.
why?

I trued passing file=file to xyplot but that appears to be ignored too.

so, how do I tell lattice::xyplot to write charts in png files?

thanks!




__
R-help@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.


[R] lattice::xyplot & file output

2012-12-20 Thread Sam Steingold
Hi,
When I was using the regular plot() function, I added this:

--8<---cut here---start->8---
  if (!is.null(file)) {
do.call(tools::file_ext(file),list(file = file))
on.exit(dev.off())
cat("writing",file,"\n")
  }
--8<---cut here---end--->8---

to the beginning of each of my functions which plotted anything.
now that I am using lattice::xyplot to plot multiple lines, the above
code does NOT result in the plot being written to a file.
why?

I trued passing file=file to xyplot but that appears to be ignored too.

so, how do I tell lattice::xyplot to write charts in png files?

thanks!


-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://honestreporting.com
http://jihadwatch.org http://think-israel.org http://mideasttruth.com
cogito cogito ergo cogito sum

__
R-help@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.


Re: [R] lattice xyplot, get current level

2012-10-02 Thread David Winsemius

On Oct 2, 2012, at 3:59 AM, Christof Kluß wrote:

> Hi
> 
> xyplot(y ~ x | subject) plots a separate graph of y against x for each
> level of subject. But I would like to have an own function for each
> level. Something like
> 
> xyplot(y ~ x | subject,
>   panel = function(x,y) {
> panel.xyplot(x,y)
> 
> panel.curve(x,y) {
>   # something that dependents on the current subject
>   ...
> }
>   })
> 

This seems to be different question than what you later requested. This 
question would seem to be documented in the 'panel' section of help(xyplot) in 
particular the paragraph beginning with this sentence:

"One can also use functions called panel.number and packet.number, representing 
panel order and packet order respectively, inside the panel function (as well 
as the strip function or while interacting with a lattice display using 
trellis.focus etc). "

-- 

David Winsemius, MD
Alameda, CA, USA

__
R-help@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.


Re: [R] lattice xyplot, get current level

2012-10-02 Thread Bert Gunter
Christof:

You are aware, I assume, that the subject level name can be
incorporated into the strip label via the "strip" function argument;
e.g.

xyplot(...,
strip = strip.custom(style = 1, strip.levels=c(TRUE,TRUE)),
...)

Cheers,
Bert

On Tue, Oct 2, 2012 at 6:45 AM, Christof Kluß  wrote:
> subj <- levels(subject)
> subj[panel.number()]
>
> seems to be a good solution
>
> is there something like panel.legend (instead of panel.text)?
>
> Am 02-10-2012 12:59, schrieb Christof Kluß:
>> Hi
>>
>> xyplot(y ~ x | subject) plots a separate graph of y against x for each
>> level of subject. But I would like to have an own function for each
>> level. Something like
>>
>> xyplot(y ~ x | subject,
>>panel = function(x,y) {
>>  panel.xyplot(x,y)
>>
>>  panel.curve(x,y) {
>># something that dependents on the current subject
>>...
>>  }
>>})
>>
>>
>> How I get the current subject? (The current subject is the title of the
>> graph, too)
>>
>> thx
>> Christof
>>
>
> __
> R-help@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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@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.


Re: [R] lattice xyplot, get current level

2012-10-02 Thread Christof Kluß
subj <- levels(subject)
subj[panel.number()]

seems to be a good solution

is there something like panel.legend (instead of panel.text)?

Am 02-10-2012 12:59, schrieb Christof Kluß:
> Hi
> 
> xyplot(y ~ x | subject) plots a separate graph of y against x for each
> level of subject. But I would like to have an own function for each
> level. Something like
> 
> xyplot(y ~ x | subject,
>panel = function(x,y) {
>  panel.xyplot(x,y)
> 
>  panel.curve(x,y) {
># something that dependents on the current subject
>...
>  }
>})
> 
> 
> How I get the current subject? (The current subject is the title of the
> graph, too)
> 
> thx
> Christof
>

__
R-help@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.


[R] lattice xyplot, get current level

2012-10-02 Thread Christof Kluß
Hi

xyplot(y ~ x | subject) plots a separate graph of y against x for each
level of subject. But I would like to have an own function for each
level. Something like

xyplot(y ~ x | subject,
   panel = function(x,y) {
 panel.xyplot(x,y)

 panel.curve(x,y) {
   # something that dependents on the current subject
   ...
 }
   })


How I get the current subject? (The current subject is the title of the
graph, too)

thx
Christof

__
R-help@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.


Re: [R] Lattice xyplot log scale labels help!

2011-11-20 Thread Deepayan Sarkar
On Fri, Sep 16, 2011 at 6:56 PM, Deepayan Sarkar
 wrote:
> On Fri, Sep 16, 2011 at 2:17 AM, Cram Rigby  wrote:
>> I have a problem with lattice log scales that I could use some help with.
>>
>> I'm trying to print log y-axis scales without exponents in the labels.
>>  A similar thread with Deepayan' recommendation is here:
>> http://tolstoy.newcastle.edu.au/R/e11/help/10/09/9865.html.  For
>> example, this code using xyplot produces a logged y-axis but the
>> labels  (e.g. "10^1.2") are not very user-friendly:
>>
>> xyplot(24:300~24:300, scales=list(y=list(log=T)))
>>
>> So, trying another y.scale.component function, we get something more
>> agreeable for y-axis scale labels:
>>
>> xyplot(24:300~24:300, scales=list(y=list(log=T)), yscale.components =
>> yscale.components.log10.3)
>>
>>
>> However, my problem is that occasionally I'll have to plot data that
>> doesn't quite "work".  For example, in the following example, I only
>> get one y-axis scale label:
>>
>> xyplot(11:30~11:30, scales=list(y=list(log=T)), yscale.components =
>> yscale.components.log10.3)
>>
>> or worse, no y-axis scale labels:
>>
>> xyplot(11:19~11:19, scales=list(log=T), yscale.components =
>> yscale.components.log10.3)
>>
>>
>> What would be most helpful is if someone can show me how to use an
>> xyplot y-scale function to mimic log y-scale labels generated with the
>> standard plot command.  This seems to work regardless of the
>> underlying data range:
>>
>> plot(11:30,11:30,log = "y")
>> plot(24:300,24:300,log="y")
>
> That is because the standard graphics log-axis rules (which is
> codified in axTicks(), and depends critically on par("yaxp")) is more
> sophisticated than latticeExtra:::logTicks() (which was originally
> written as a proof-of-concept demo).
>
> To make logTicks() equally sophisticated, we need to replicate the
> logic used to compute par("yaxp") (in src/main/graphics.c, I think),
> which is doable, but not trivial.

And thanks to Martin Maechler, these nontrivial computations are now
more easily accessible outside the traditional graphics world. In the
development version of lattice (on r-forge, not yet released to CRAN),
you can do

xyplot(11:30~11:30, scales=list(y=list(log=T, equispaced.log = FALSE)))

etc. This requires R 2.14.0 or better.

-Deepayan

__
R-help@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.


Re: [R] lattice::xyplot/ggplot2: plotting weighted data frames with lmline and smooth

2011-10-21 Thread Dennis Murphy
Hi Michael:

The necessary argument to geom_smooth() is weight, not weights (my
fault, sorry), so try this instead:

ggplot(PearsonLee, aes(x = parent, y = child)) +
   geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
   geom_smooth(method = lm, aes(weight = frequency,
   colour = 'Linear'), se = FALSE, size = 1.5) +
   geom_smooth(aes(weight = frequency,
   colour = 'Loess'), se = FALSE, size = 1.5) +
   facet_grid(chl ~ par) +
   scale_colour_manual(breaks = c('Linear', 'Loess'),
   values = c('green', 'red')) +
   opts(legend.position = c(0.14, 0.885),
legend.background = theme_rect(fill = 'white'))

Dennis

On Fri, Oct 21, 2011 at 11:57 AM, Michael Friendly  wrote:
> Thanks very much, Dennis.  See below for something I don't understand.
>
> On 10/21/2011 12:15 PM, Dennis Murphy wrote:
>>
>> Hi Michael:
>>
>> Here's one way to get it from ggplot2. To avoid possible overplotting,
>> I jittered the points horizontally by ą 0.2. I also reduced the point
>> size from the default 2 and increased the line thickness to 1.5 for
>> both fitted curves. In ggplot2, the term faceting is synonymous with
>> conditioning (by groups).
>>
>> library('HistData')
>> library('ggplot2')
>> ggplot(PearsonLee, aes(x = parent, y = child)) +
>>    geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
>>    geom_smooth(method = lm, aes(weights = PearsonLee$weight),
>>                colour = 'green', se = FALSE, size = 1.5) +
>>    geom_smooth(aes(weights = PearsonLee$weight),
>>                colour = 'red', se = FALSE, size = 1.5) +
>>    facet_grid(chl ~ par)
>
> This seems to work, but I don't understand *why*, since the weight variable
> is
> PearsonLee$frequency, not PearsonLee$weight.
>
>> PearsonLee$weight
> NULL
>
> I get an error if I try to use PearsonLee$frequency as the weights=
> variable.
>
>> ggplot(PearsonLee, aes(x = parent, y = child)) +
> +    geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
> +    geom_smooth(method = lm, aes(weights = PearsonLee$frequency),
> +                colour = 'green', se = FALSE, size = 1.5) +
> +    geom_smooth(aes(weights = PearsonLee$frequency),
> +                colour = 'red', se = FALSE, size = 1.5) +
> +    facet_grid(chl ~ par)
> Error in eval(expr, envir, enclos) : object 'weight' not found
>
> In the form below, it makes sense to me and does work, using
> weight=frequency in the initial aes(),
> and weight= in geom_smooth:
>
> ggplot(PearsonLee, aes(x = parent, y = child, weight=frequency)) +
>   geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
>   geom_smooth(method = lm, aes(weight = PearsonLee$frequency),
>               colour = 'green', se = FALSE, size = 1.5) +
>   geom_smooth(aes(weight = PearsonLee$frequency),
>               colour = 'red', se = FALSE, size = 1.5) +
>   facet_grid(chl ~ par)
>
>
>> # If you prefer a legend, here's one take, pulling the legend inside
>> # to the upper left corner. This requires a bit more 'trickery', but
>> # the tricks are found in the ggplot2 book.
>>
>> ggplot(PearsonLee, aes(x = parent, y = child)) +
>>    geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
>>    geom_smooth(method = lm, aes(weights = PearsonLee$weight,
>>                colour = 'Linear'), se = FALSE, size = 1.5) +
>>    geom_smooth(aes(weights = PearsonLee$weight,
>>                colour = 'Loess'), se = FALSE, size = 1.5) +
>>    facet_grid(chl ~ par) +
>>    scale_colour_manual(breaks = c('Linear', 'Loess'),
>>                        values = c('green', 'red')) +
>>    opts(legend.position = c(0.14, 0.885),
>>         legend.background = theme_rect(fill = 'white'))
>>
>>
>> HTH,
>> Dennis
>
>
> --
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    Web:   http://www.datavis.ca
> Toronto, ONT  M3J 1P3 CANADA
>
>
>

__
R-help@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.


Re: [R] lattice::xyplot/ggplot2: plotting weighted data frames with lmline and smooth

2011-10-21 Thread Michael Friendly

Thanks very much, Dennis.  See below for something I don't understand.

On 10/21/2011 12:15 PM, Dennis Murphy wrote:

Hi Michael:

Here's one way to get it from ggplot2. To avoid possible overplotting,
I jittered the points horizontally by ± 0.2. I also reduced the point
size from the default 2 and increased the line thickness to 1.5 for
both fitted curves. In ggplot2, the term faceting is synonymous with
conditioning (by groups).

library('HistData')
library('ggplot2')
ggplot(PearsonLee, aes(x = parent, y = child)) +
geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
geom_smooth(method = lm, aes(weights = PearsonLee$weight),
colour = 'green', se = FALSE, size = 1.5) +
geom_smooth(aes(weights = PearsonLee$weight),
colour = 'red', se = FALSE, size = 1.5) +
facet_grid(chl ~ par)
This seems to work, but I don't understand *why*, since the weight 
variable is

PearsonLee$frequency, not PearsonLee$weight.

> PearsonLee$weight
NULL

I get an error if I try to use PearsonLee$frequency as the weights= 
variable.


> ggplot(PearsonLee, aes(x = parent, y = child)) +
+geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
+geom_smooth(method = lm, aes(weights = PearsonLee$frequency),
+colour = 'green', se = FALSE, size = 1.5) +
+geom_smooth(aes(weights = PearsonLee$frequency),
+colour = 'red', se = FALSE, size = 1.5) +
+facet_grid(chl ~ par)
Error in eval(expr, envir, enclos) : object 'weight' not found

In the form below, it makes sense to me and does work, using 
weight=frequency in the initial aes(),

and weight= in geom_smooth:

ggplot(PearsonLee, aes(x = parent, y = child, weight=frequency)) +
   geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
   geom_smooth(method = lm, aes(weight = PearsonLee$frequency),
   colour = 'green', se = FALSE, size = 1.5) +
   geom_smooth(aes(weight = PearsonLee$frequency),
   colour = 'red', se = FALSE, size = 1.5) +
   facet_grid(chl ~ par)



# If you prefer a legend, here's one take, pulling the legend inside
# to the upper left corner. This requires a bit more 'trickery', but
# the tricks are found in the ggplot2 book.

ggplot(PearsonLee, aes(x = parent, y = child)) +
geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
geom_smooth(method = lm, aes(weights = PearsonLee$weight,
colour = 'Linear'), se = FALSE, size = 1.5) +
geom_smooth(aes(weights = PearsonLee$weight,
colour = 'Loess'), se = FALSE, size = 1.5) +
facet_grid(chl ~ par) +
scale_colour_manual(breaks = c('Linear', 'Loess'),
values = c('green', 'red')) +
opts(legend.position = c(0.14, 0.885),
 legend.background = theme_rect(fill = 'white'))


HTH,
Dennis



--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@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.


Re: [R] lattice::xyplot/ggplot2: plotting weighted data frames with lmline and smooth

2011-10-21 Thread Dennis Murphy
Hi Michael:

Here's one way to get it from ggplot2. To avoid possible overplotting,
I jittered the points horizontally by +/- 0.2. I also reduced the point
size from the default 2 and increased the line thickness to 1.5 for
both fitted curves. In ggplot2, the term faceting is synonymous with
conditioning (by groups).

library('HistData')
library('ggplot2')
ggplot(PearsonLee, aes(x = parent, y = child)) +
   geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
   geom_smooth(method = lm, aes(weights = PearsonLee$weight),
   colour = 'green', se = FALSE, size = 1.5) +
   geom_smooth(aes(weights = PearsonLee$weight),
   colour = 'red', se = FALSE, size = 1.5) +
   facet_grid(chl ~ par)

# If you prefer a legend, here's one take, pulling the legend inside
# to the upper left corner. This requires a bit more 'trickery', but
# the tricks are found in the ggplot2 book.

ggplot(PearsonLee, aes(x = parent, y = child)) +
   geom_point(size = 1.5, position = position_jitter(width = 0.2)) +
   geom_smooth(method = lm, aes(weights = PearsonLee$weight,
   colour = 'Linear'), se = FALSE, size = 1.5) +
   geom_smooth(aes(weights = PearsonLee$weight,
   colour = 'Loess'), se = FALSE, size = 1.5) +
   facet_grid(chl ~ par) +
   scale_colour_manual(breaks = c('Linear', 'Loess'),
   values = c('green', 'red')) +
   opts(legend.position = c(0.14, 0.885),
legend.background = theme_rect(fill = 'white'))


HTH,
Dennis

On Fri, Oct 21, 2011 at 8:22 AM, Michael Friendly  wrote:
> In the HistData package, I have a data frame, PearsonLee, containing
> observations on heights of parent and child, in weighted form:
>
> library(HistData)
>
>> str(PearsonLee)
> 'data.frame':   746 obs. of  6 variables:
>  $ child    : num  59.5 59.5 59.5 60.5 60.5 61.5 61.5 61.5 61.5 61.5 ...
>  $ parent   : num  62.5 63.5 64.5 62.5 66.5 59.5 60.5 62.5 63.5 64.5 ...
>  $ frequency: num  0.5 0.5 1 0.5 1 0.25 0.25 0.5 1 0.25 ...
>  $ gp       : Factor w/ 4 levels "fd","fs","md",..: 2 2 2 2 2 2 2 2 2 2 ...
>  $ par      : Factor w/ 2 levels "Father","Mother": 1 1 1 1 1 1 1 1 1 1 ...
>  $ chl      : Factor w/ 2 levels "Daughter","Son": 2 2 2 2 2 2 2 2 2 2 ...
>
> I want to make a 2x2 set of plots of child ~ parent | par+chl, with
> regression lines and loess smooths, that
> incorporate weights=frequency.  The "frequencies" are not integers, so I
> can't simply expand the
> data frame.
>
> I'd also like to use different colors for the regression and smoothed lines.
> Here's what I've tried using xyplot, all unsuccessful.  I suppose I could
> also use ggplot2, if I could do what
> I want.
>
> xyplot(child ~ parent|par+chl, data=PearsonLee, weights=frequency,
> type=c("p", "r", "smooth"))
> xyplot(child ~ parent|par+chl, data=PearsonLee,  type=c("p", "r", "smooth"))
>
>  panel.lmline  and panel.smooth don't have a weights= argument, though lm()
> and loess() do.
>
> # Try to control line colors: unsuccessfully -- only one value of col.lin is
> used
> xyplot(child ~ parent|par+chl, data=PearsonLee, type=c("p", "r", "smooth"),
> col.line=c("red", "blue"))
>
> ## try to use panel functions ... unsucessfully
> xyplot(child ~ parent|par+chl, data=PearsonLee, type="p",
>       panel = function(x, y, ...) {
>           panel.xyplot(x, y, ...)
>           panel.lmline(x, y, col="blue", ...)
>           panel.smooth(x, y, col="red", ...)
>           }
> )
>
> The following, using base graphics, illustrates the difference between the
> weighted and unweighted lines,
> for the total data frame:
>
> with(PearsonLee,
>    {
>    lim <- c(55,80)
>    xv <- seq(55,80, .5)
>    sunflowerplot(parent,child, number=frequency, xlim=lim, ylim=lim,
> seg.col="gray", size=.1)
>    # unweighted
>    abline(lm(child ~ parent), col="green", lwd=2)
>    lines(xv, predict(loess(child ~ parent), data.frame(parent=xv)),
> col="green", lwd=2)
>    # weighted
>    abline(lm(child ~ parent, weights=frequency), col="blue", lwd=2)
>    lines(xv, predict(loess(child ~ parent, weights=frequency),
> data.frame(parent=xv)), col="blue", lwd=2)
>  })
>
> thanks,
> -Michael
>
>
>
> --
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    Web:   http://www.datavis.ca
> Toronto, ONT  M3J 1P3 CANADA
>
> __
> R-help@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.
>

__
R-help@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.


[R] lattice::xyplot/ggplot2: plotting weighted data frames with lmline and smooth

2011-10-21 Thread Michael Friendly
In the HistData package, I have a data frame, PearsonLee, containing 
observations on heights of parent and child, in weighted form:


library(HistData)

> str(PearsonLee)
'data.frame':   746 obs. of  6 variables:
 $ child: num  59.5 59.5 59.5 60.5 60.5 61.5 61.5 61.5 61.5 61.5 ...
 $ parent   : num  62.5 63.5 64.5 62.5 66.5 59.5 60.5 62.5 63.5 64.5 ...
 $ frequency: num  0.5 0.5 1 0.5 1 0.25 0.25 0.5 1 0.25 ...
 $ gp   : Factor w/ 4 levels "fd","fs","md",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ par  : Factor w/ 2 levels "Father","Mother": 1 1 1 1 1 1 1 1 1 1 ...
 $ chl  : Factor w/ 2 levels "Daughter","Son": 2 2 2 2 2 2 2 2 2 2 ...

I want to make a 2x2 set of plots of child ~ parent | par+chl, with 
regression lines and loess smooths, that
incorporate weights=frequency.  The "frequencies" are not integers, so I 
can't simply expand the

data frame.

I'd also like to use different colors for the regression and smoothed lines.
Here's what I've tried using xyplot, all unsuccessful.  I suppose I 
could also use ggplot2, if I could do what

I want.

xyplot(child ~ parent|par+chl, data=PearsonLee, weights=frequency, 
type=c("p", "r", "smooth"))

xyplot(child ~ parent|par+chl, data=PearsonLee,  type=c("p", "r", "smooth"))

 panel.lmline  and panel.smooth don't have a weights= argument, though 
lm() and loess() do.


# Try to control line colors: unsuccessfully -- only one value of 
col.lin is used
xyplot(child ~ parent|par+chl, data=PearsonLee, type=c("p", "r", 
"smooth"), col.line=c("red", "blue"))


## try to use panel functions ... unsucessfully
xyplot(child ~ parent|par+chl, data=PearsonLee, type="p",
   panel = function(x, y, ...) {
   panel.xyplot(x, y, ...)
   panel.lmline(x, y, col="blue", ...)
   panel.smooth(x, y, col="red", ...)
   }
)

The following, using base graphics, illustrates the difference between 
the weighted and unweighted lines,

for the total data frame:

with(PearsonLee,
{
lim <- c(55,80)
xv <- seq(55,80, .5)
sunflowerplot(parent,child, number=frequency, xlim=lim, ylim=lim, 
seg.col="gray", size=.1)

# unweighted
abline(lm(child ~ parent), col="green", lwd=2)
lines(xv, predict(loess(child ~ parent), data.frame(parent=xv)), 
col="green", lwd=2)

# weighted
abline(lm(child ~ parent, weights=frequency), col="blue", lwd=2)
lines(xv, predict(loess(child ~ parent, weights=frequency), 
data.frame(parent=xv)), col="blue", lwd=2)

  })

thanks,
-Michael



--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@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.


Re: [R] Lattice xyplot log scale labels help!

2011-09-16 Thread Deepayan Sarkar
On Fri, Sep 16, 2011 at 2:17 AM, Cram Rigby  wrote:
> I have a problem with lattice log scales that I could use some help with.
>
> I'm trying to print log y-axis scales without exponents in the labels.
>  A similar thread with Deepayan' recommendation is here:
> http://tolstoy.newcastle.edu.au/R/e11/help/10/09/9865.html.  For
> example, this code using xyplot produces a logged y-axis but the
> labels  (e.g. "10^1.2") are not very user-friendly:
>
> xyplot(24:300~24:300, scales=list(y=list(log=T)))
>
> So, trying another y.scale.component function, we get something more
> agreeable for y-axis scale labels:
>
> xyplot(24:300~24:300, scales=list(y=list(log=T)), yscale.components =
> yscale.components.log10.3)
>
>
> However, my problem is that occasionally I'll have to plot data that
> doesn't quite "work".  For example, in the following example, I only
> get one y-axis scale label:
>
> xyplot(11:30~11:30, scales=list(y=list(log=T)), yscale.components =
> yscale.components.log10.3)
>
> or worse, no y-axis scale labels:
>
> xyplot(11:19~11:19, scales=list(log=T), yscale.components =
> yscale.components.log10.3)
>
>
> What would be most helpful is if someone can show me how to use an
> xyplot y-scale function to mimic log y-scale labels generated with the
> standard plot command.  This seems to work regardless of the
> underlying data range:
>
> plot(11:30,11:30,log = "y")
> plot(24:300,24:300,log="y")

That is because the standard graphics log-axis rules (which is
codified in axTicks(), and depends critically on par("yaxp")) is more
sophisticated than latticeExtra:::logTicks() (which was originally
written as a proof-of-concept demo).

To make logTicks() equally sophisticated, we need to replicate the
logic used to compute par("yaxp") (in src/main/graphics.c, I think),
which is doable, but not trivial.

-Deepayan

__
R-help@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.


[R] Lattice xyplot log scale labels help!

2011-09-15 Thread Cram Rigby
I have a problem with lattice log scales that I could use some help with.

I'm trying to print log y-axis scales without exponents in the labels.
 A similar thread with Deepayan' recommendation is here:
http://tolstoy.newcastle.edu.au/R/e11/help/10/09/9865.html.  For
example, this code using xyplot produces a logged y-axis but the
labels  (e.g. "10^1.2") are not very user-friendly:

xyplot(24:300~24:300, scales=list(y=list(log=T)))

So, trying another y.scale.component function, we get something more
agreeable for y-axis scale labels:

xyplot(24:300~24:300, scales=list(y=list(log=T)), yscale.components =
yscale.components.log10.3)


However, my problem is that occasionally I'll have to plot data that
doesn't quite "work".  For example, in the following example, I only
get one y-axis scale label:

xyplot(11:30~11:30, scales=list(y=list(log=T)), yscale.components =
yscale.components.log10.3)

or worse, no y-axis scale labels:

xyplot(11:19~11:19, scales=list(log=T), yscale.components =
yscale.components.log10.3)


What would be most helpful is if someone can show me how to use an
xyplot y-scale function to mimic log y-scale labels generated with the
standard plot command.  This seems to work regardless of the
underlying data range:

plot(11:30,11:30,log = "y")
plot(24:300,24:300,log="y")


Thanks for any input!

__
R-help@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.


Re: [R] Lattice xyplot to group by two parameters

2011-06-24 Thread Deepayan Sarkar
On Thu, Jun 23, 2011 at 10:15 PM, Guy Jett  wrote:
> My thanks to this mailing list and its members for their great help in the 
> past.  I have yet another question per the following code and comments:
>
> # I need individual graphs grouped by "PARLABEL" AND "Event", with "PARLABEL"
> #   controlling pct and lty, and "Event" controlling col (where Event==1 is 
> green
> #   and Event==2 is red). This is attempted in the xyplot parameter
> #   "groups = c(PARLABEL, Event)". Current behavior appears to be that the
> #   colors are controlled by "PARLABEL" along with the shape and line type.  
> Some
> #   experimentation with those two parameters (reverse order, one or the 
> other only)
> #   suggests that the second parameter is ignored.

[Please let me know which part of the documentation suggested anything
otherwise, and I will try to fix it.]

> # I have also experimented with panel.superpose, subsetting, and Extended 
> formula
> #   interface, as appears to be suggested by the "man pages", but to no avail.

Here is an example you should be able to adapt:

http://lmdvr.r-forge.r-project.org/figures/figures.html?chapter=09;figure=09_02;theme=stdBW;code=right

-Deepayan


> #   Note that I can get the graphics layout I need with ggplot2, but that has 
> its
> #   own issues with secondary axis and subtitle text placement, formatting, 
> and
> #   pagination.
> #
> # Example script below.  Datafile included.
>
>  depthlimit=c(7,-1)
>  xlimit=c(0.1,125000)
>  TransectOrder = c("LLR19", "LLR18", "LLR17")
>
>  OffsetOrder  =  c("T", "U", "V", "Y", "Z",
>                    "A", "B", "C", "D", "E", "F", "G", "H")
>
> # Parse the data for these plots -
>  df <- read.csv(file = "5.04-r02_LTC-SE-SO-Compared.csv")
>  df$Transect <- factor(df$Transect, levels = TransectOrder)
>  levels(df$Transect)
>  df$Offset <- factor(df$Offset, levels = OffsetOrder)
>  levels(df$Offset)
>
>    xyplot((sbd+sed)/2 ~ Result | Offset+Transect, groups = c(PARLABEL, Event),
>      as.table = TRUE,
>      drop.unused.levels = FALSE, data = df,
>      layout = c(13,3), type = "b",
>      xlim = c(0.01, 122000), ylim = depthlimit,
>      pch  =c(16, 18), cex = c(1, 1), # to be controlled by "PARLABEL"
>      lty  =c("dashed", "solid"),     # to be controlled by "PARLABEL"
>      col = c("green", "red"),        # to be controlled by "Event"
>      scales = list(alternating = 1, x = list(rot = 45, log = TRUE)))
>
> Yours,
> Guy Jett, R.G.
> Project Geologist
> ITSI,  A Gilbane Company
> gj...@itsi.com
>
>
> __
> R-help@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.
>
>

__
R-help@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.


[R] Lattice xyplot to group by two parameters

2011-06-23 Thread Guy Jett
My thanks to this mailing list and its members for their great help in the 
past.  I have yet another question per the following code and comments:

# I need individual graphs grouped by "PARLABEL" AND "Event", with "PARLABEL"
#   controlling pct and lty, and "Event" controlling col (where Event==1 is 
green
#   and Event==2 is red). This is attempted in the xyplot parameter
#   "groups = c(PARLABEL, Event)". Current behavior appears to be that the
#   colors are controlled by "PARLABEL" along with the shape and line type.  
Some 
#   experimentation with those two parameters (reverse order, one or the other 
only)
#   suggests that the second parameter is ignored.
#
# I have also experimented with panel.superpose, subsetting, and Extended 
formula
#   interface, as appears to be suggested by the "man pages", but to no avail. 
#   
#   Note that I can get the graphics layout I need with ggplot2, but that has 
its
#   own issues with secondary axis and subtitle text placement, formatting, and 
#   pagination.
#
# Example script below.  Datafile included. 

  depthlimit=c(7,-1)
  xlimit=c(0.1,125000)
  TransectOrder = c("LLR19", "LLR18", "LLR17")

  OffsetOrder  =  c("T", "U", "V", "Y", "Z",
"A", "B", "C", "D", "E", "F", "G", "H")

# Parse the data for these plots -
  df <- read.csv(file = "5.04-r02_LTC-SE-SO-Compared.csv")
  df$Transect <- factor(df$Transect, levels = TransectOrder)
  levels(df$Transect)
  df$Offset <- factor(df$Offset, levels = OffsetOrder)
  levels(df$Offset)

xyplot((sbd+sed)/2 ~ Result | Offset+Transect, groups = c(PARLABEL, Event),
  as.table = TRUE,
  drop.unused.levels = FALSE, data = df,
  layout = c(13,3), type = "b",
  xlim = c(0.01, 122000), ylim = depthlimit,
  pch  =c(16, 18), cex = c(1, 1), # to be controlled by "PARLABEL"
  lty  =c("dashed", "solid"), # to be controlled by "PARLABEL"
  col = c("green", "red"),# to be controlled by "Event"
  scales = list(alternating = 1, x = list(rot = 45, log = TRUE)))

Yours,
Guy Jett, R.G.
Project Geologist
ITSI,  A Gilbane Company
gj...@itsi.com

__
R-help@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.


Re: [R] [lattice xyplot] Help needed in help in customizing the panel.abline() function

2010-12-10 Thread Girish A.R.

Thanks, Felix! That works.

best,
-Girish
-- 
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3081792.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] [lattice xyplot] Help needed in help in customizing the panel.abline() function

2010-12-10 Thread Felix Andrews
Hi Girish,

Try this:

disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
"h",lwd=2,panel = function(x, y, ...) {
  panel.abline(v = x[which.max(y)], lty = 2)
  panel.xyplot(x, y, ...)
  })

-Felix


On 9 December 2010 17:35, Girish A.R.  wrote:
>
> Hi folks,
>
> I need some help in customizing the abline() function to be used in a
> lattice plot. I have attached a reproducible example below.
>
> I need help in the following snippet:
> disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
> "h",lwd=2,panel = function(...) {
>           panel.abline(v = 8, lty = 2)
>           panel.xyplot(...)
>       })
>
> Is there a way I can give panel.abline() input from a which.max() function?
> Essentially I need the vertical line to be drawn at the week_num
> corresponding to the max (cnt_gt50pct_disc).
>
> Thanks in advance,
>
> -Girish
>
> ===
> Lines <- "sku_num week_num    pct_inv_left    cnt_gt50pct_disc
> 1   1   99.88   47
> 1   2   99.54   109
> 1   3   98.7    260
> 1   4   97.83   202
> 1   5   96.53   389
> 1   6   94.11   450
> 1   7   90.42   459
> 1   8   86.63   448
> 1   9   83.39   411
> 1   10  77  478
> 1   11  71.65   476
> 1   12  67.3    463
> 1   13  62.45   472
> 1   14  52.47   488
> 1   15  40.86   486
> 1   16  31.34   484
> 1   17  23.2    472
> 1   18  17  458
> 1   19  12.66   423
> 1   20  10.18   364
> 1   21  7.6 343
> 1   22  3.09    343
> 1   23  1.05    211
> 2   1   99.94   30
> 2   2   99.4    151
> 2   3   98.85   146
> 2   4   97.92   274
> 2   5   97.03   204
> 2   6   95.59   378
> 2   7   92.81   452
> 2   8   89.07   470
> 2   9   85.11   454
> 2   10  81.68   421
> 2   11  75.34   479
> 2   12  70.05   476
> 2   13  66.11   456
> 2   14  61.85   465
> 2   15  53.2    485
> 2   16  42.75   486
> 2   17  33.58   481
> 2   18  25  477
> 2   19  18.13   450
> 2   20  12.97   416
> 2   21  10.03   343
> 2   22  7.03    293
> 2   23  2.33    283
> 2   24  0.77    116
> "
>
> DF <- read.table(con<- textConnection(Lines), skip = 1);
> names(DF) <- scan(textConnection(Lines), what = "", nlines = 1) ;
> close(con);
>
> require(latticeExtra)
> DF$sku_num <- as.factor(DF$sku_num)
> disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
> "h",lwd=2,panel = function(...) {
>           panel.abline(v = 8, lty = 2)
>           panel.xyplot(...)
>       })
> sales <- xyplot(pct_inv_left  ~ week_num|sku_num, data=swtop16,type =
> "l",lwd=2,panel = function(...) {
>           panel.abline(h = 75, lty = 2)
>           panel.xyplot(...)
>       })
> doubleYScale(disc, sales, style1 = 0, style2 = 2, add.ylab2 = TRUE,text =
> c("# stores with gt 50pct disc", "% Unsold"))
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3079656.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>



-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/

__
R-help@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.


Re: [R] [lattice xyplot] Help needed in help in customizing the panel.abline() function

2010-12-08 Thread Girish A.R.

Thanks for the reply, Dieter.

I'm sorry I should have made it clear in my original post - the number
(output of which.max()) IS dependent on the grouping..

Thanks,
-Girish
-- 
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3079705.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] [lattice xyplot] Help needed in help in customizing the panel.abline() function

2010-12-08 Thread Dieter Menne


Girish A.R. wrote:
> 
> Sorry, just realized that there was a typo in the following code of my
> original post. The correct code is as shown below (corrected
> 'data=swtop16' to 'data=DF'):
> 
> sales <- xyplot(pct_inv_left  ~ week_num|sku_num, data=DF,type =
> "l",lwd=2,panel = function(...) {
>panel.abline(h = 75, lty = 2)
>panel.xyplot(...)
>}) 
> 
> 
If it is really a constant not dependent on grouping, you could compute it
in the parent; or, better probably, compute it in panel.abline()

Dieter

.. Your data here ...

maxWeek = DF$week_num[which.max (DF$cnt_gt50pct_disc)]

sales <- xyplot(pct_inv_left  ~ week_num|sku_num, data=DF,type =
"l",lwd=2,panel = function(...) {
   panel.abline(h = 75, lty = 2)
   panel.abline(v = maxWeek, lty = 2)
   panel.xyplot(...)
   })
print(sales)




-- 
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3079698.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] [lattice xyplot] Help needed in help in customizing the panel.abline() function

2010-12-08 Thread Dieter Menne


-- 
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3079697.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] [lattice xyplot] Help needed in help in customizing the panel.abline() function

2010-12-08 Thread Girish A.R.

Sorry, just realized that there was a typo in the following code of my
original post. The correct code is as shown below (corrected 'data=swtop16'
to 'data=DF'):

sales <- xyplot(pct_inv_left  ~ week_num|sku_num, data=DF,type =
"l",lwd=2,panel = function(...) {
   panel.abline(h = 75, lty = 2)
   panel.xyplot(...)
   }) 

Thanks,
-Girish

-- 
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3079666.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] [lattice xyplot] Help needed in help in customizing the panel.abline() function

2010-12-08 Thread Girish A.R.

Hi folks,

I need some help in customizing the abline() function to be used in a
lattice plot. I have attached a reproducible example below. 

I need help in the following snippet:
disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
"h",lwd=2,panel = function(...) {
   panel.abline(v = 8, lty = 2)
   panel.xyplot(...)
   })

Is there a way I can give panel.abline() input from a which.max() function?
Essentially I need the vertical line to be drawn at the week_num
corresponding to the max (cnt_gt50pct_disc). 

Thanks in advance,

-Girish 

===
Lines <- "sku_num week_numpct_inv_leftcnt_gt50pct_disc
1   1   99.88   47
1   2   99.54   109
1   3   98.7260
1   4   97.83   202
1   5   96.53   389
1   6   94.11   450
1   7   90.42   459
1   8   86.63   448
1   9   83.39   411
1   10  77  478
1   11  71.65   476
1   12  67.3463
1   13  62.45   472
1   14  52.47   488
1   15  40.86   486
1   16  31.34   484
1   17  23.2472
1   18  17  458
1   19  12.66   423
1   20  10.18   364
1   21  7.6 343
1   22  3.09343
1   23  1.05211
2   1   99.94   30
2   2   99.4151
2   3   98.85   146
2   4   97.92   274
2   5   97.03   204
2   6   95.59   378
2   7   92.81   452
2   8   89.07   470
2   9   85.11   454
2   10  81.68   421
2   11  75.34   479
2   12  70.05   476
2   13  66.11   456
2   14  61.85   465
2   15  53.2485
2   16  42.75   486
2   17  33.58   481
2   18  25  477
2   19  18.13   450
2   20  12.97   416
2   21  10.03   343
2   22  7.03293
2   23  2.33283
2   24  0.77116
"

DF <- read.table(con<- textConnection(Lines), skip = 1);
names(DF) <- scan(textConnection(Lines), what = "", nlines = 1) ;
close(con); 

require(latticeExtra)
DF$sku_num <- as.factor(DF$sku_num)
disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
"h",lwd=2,panel = function(...) {
   panel.abline(v = 8, lty = 2)
   panel.xyplot(...)
   })
sales <- xyplot(pct_inv_left  ~ week_num|sku_num, data=swtop16,type =
"l",lwd=2,panel = function(...) {
   panel.abline(h = 75, lty = 2)
   panel.xyplot(...)
   })
doubleYScale(disc, sales, style1 = 0, style2 = 2, add.ylab2 = TRUE,text =
c("# stores with gt 50pct disc", "% Unsold"))
-- 
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3079656.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Lattice: xyplot group title format

2010-11-09 Thread Deepayan Sarkar
On Tue, Nov 9, 2010 at 2:06 AM, Marcus Drescher  wrote:
> Dear all,
>
> if I plot a lattice xyplot like:
>
> library(lattice); require(stats);
> Depth <- equal.count(quakes$depth, number=8, overlap=.1)
>
> xyplot(lat ~ long | Depth, data = quakes)
>
>
> How can I manipulate the group title format (here: Depth)? Like the font 
> size, position, etc.

See ?strip.default

-Deepayan

__
R-help@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.


[R] Lattice: xyplot group title format

2010-11-09 Thread Marcus Drescher
Dear all,

if I plot a lattice xyplot like:

library(lattice); require(stats);
Depth <- equal.count(quakes$depth, number=8, overlap=.1)

xyplot(lat ~ long | Depth, data = quakes)


How can I manipulate the group title format (here: Depth)? Like the font size, 
position, etc.

Best
Marcus 

__
R-help@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.


Re: [R] lattice xyplot - formatting of multiple Y variables when using subgroups

2010-10-17 Thread Prasenjit Kapat
On Sun, Oct 17, 2010 at 10:01 AM, Coen van Hasselt
 wrote:
> Hi all,
>
> Using xyplot I want to print to Y variables (y1, y2) versus X, conditional
> on the group.
> How can I obtain a line (type="l") for one relationship (ie. y1 ~ x) and
> points (type="p") for the other (y2 ~ x) ?
>
> library(lattice)
>
> # create some sample data
> df<-data.frame(group=as.factor(c(rep("a",4), rep("b",4))), # grouping
> variable for conditional plots
>    x=c(1:4,1:4), # x variable
>    y1=rnorm(4,0,1), # y1
>    y2=rnorm(4,0,1)) # y2
>
>
> # Basically I want this plot, but then for y1~x points and for y2~x lines.
> xyplot(y1+y2 ~ x|group, data=df)
>
> # This works, but then I get the same plot in the two grouping windows
> because conditioning is lost in the panel function.
> xyplot(y1+y2 ~ x|group, data=df, type="l",
>    panel=function(...){panel.xyplot(df$x,df$y1);
>            panel.xyplot(df$x,df$y1, type="l")})

Try:

xyplot(y1+y2 ~ x|group, data=df, type=c("l","p"),
   panel=panel.superpose, distribute.type = TRUE)

> Thanks for your help.
>
> Coen

-- 
Prasenjit

__
R-help@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.


[R] lattice xyplot - formatting of multiple Y variables when using subgroups

2010-10-17 Thread Coen van Hasselt
Hi all,

Using xyplot I want to print to Y variables (y1, y2) versus X, conditional
on the group.
How can I obtain a line (type="l") for one relationship (ie. y1 ~ x) and
points (type="p") for the other (y2 ~ x) ?

library(lattice)

# create some sample data
df<-data.frame(group=as.factor(c(rep("a",4), rep("b",4))), # grouping
variable for conditional plots
x=c(1:4,1:4), # x variable
y1=rnorm(4,0,1), # y1
y2=rnorm(4,0,1)) # y2


# Basically I want this plot, but then for y1~x points and for y2~x lines.
xyplot(y1+y2 ~ x|group, data=df)

# This works, but then I get the same plot in the two grouping windows
because conditioning is lost in the panel function.
xyplot(y1+y2 ~ x|group, data=df, type="l",
panel=function(...){panel.xyplot(df$x,df$y1);
panel.xyplot(df$x,df$y1, type="l")})

Thanks for your help.

Coen

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Lattice xyplot and groups

2010-09-24 Thread Axel
> That would be the logically correct approach. Here are a couple of
> ways to specify color:

That's perfect! Thank you very much.

__
R-help@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.


Re: [R] Lattice xyplot and groups

2010-09-24 Thread Deepayan Sarkar
On Wed, Sep 22, 2010 at 12:21 AM, Axel  wrote:
> Hi,
>
> I'm trying to plot many (x, y) data files using the xyplot function
> from the lattice package. Each file can be classified by set name (s1,
> s2,...) and data type (A, B, ...). Each data set contains a different
> number of files. If the data is grouped by type or set and visualized
> as line plot with xyplot(type='l'), the first and last point are
> joined into a closed line that traverses the whole plot from left to
> right.
> This is an example showing the problem:
>
> library(lattice)
> x1 <- seq(-10, 10, 0.5)
> x2 <- seq(-10, 10, 0.1)
>
> df <- data.frame(x=x1, y=sin(x1), id='1a_s1', type='A', set='s1')
> df <- rbind(df, data.frame(x=x1, y=cos(x1), id='1b_s1', type='B', set='s1'))
> df <- rbind(df, data.frame(x=x1, y=3*sin(2*x1), id='2a_s1', type='A', 
> set='s1'))
> df <- rbind(df, data.frame(x=x1, y=3*cos(2*x1), id='2b_s1', type='B', 
> set='s1'))
>
> df <- rbind(df, data.frame(x=x2, y=sin(x2), id='1a_s1', type='A', set='s2'))
> df <- rbind(df, data.frame(x=x2, y=cos(x2), id='1b_s1', type='B', set='s2'))
> df <- rbind(df, data.frame(x=x2, y=3*sin(2*x2), id='2a_s1', type='A', 
> set='s2'))
> df <- rbind(df, data.frame(x=x2, y=3*cos(2*x2), id='2b_s1', type='B', 
> set='s2'))
>
> p=xyplot(y~x|set, df, type='l', group=type, auto.key = list(points =
> FALSE, lines = TRUE, columns = 2))
> print(p)
>
> I would really appreciate if you could suggest a way to keep the lines
> open, either by changing the plot command or by building the data
> frame in a better way. One solution would be to group by id, but then
> I don't know if it is possible to make the line color the same for a
> given data type.

That would be the logically correct approach. Here are a couple of
ways to specify color:

xyplot(y~x|set, df, type='l', groups=id,
   auto.key = list(text = c("A", "B"), lines = TRUE, points =
FALSE, columns = 2),
   par.settings = list(superpose.line =
Rows(trellis.par.get("superpose.line"), 1:2)))

xyplot(y~x|set, df, type='l', groups=id,
   auto.key = list(text = c("A", "B"), lines = TRUE, points =
FALSE, columns = 2),
   par.settings = simpleTheme(col = c("blue", "red")))

-Deepayan

__
R-help@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.


Re: [R] Lattice xyplot and groups

2010-09-21 Thread Axel
> Does using
>
>     df = df[order(df$type,df$set,df$x),]
>
> before calling xyplot fix the problem?

Thank you very much for your suggestion. It does make the lines open,
but unfortunately it mixes different id together.
With the new ordering the plot looks something like this:

(x=-10, y_id1) -> (x=-10, y_id2) -> (x=-9.5, y_id1) -> (x=-9.5, y_id2)...

I tried many combinations. It seems that when df$id is sorted before
df$dx the plot has a loop. In the other case the ids get mixed.

By the way, my previous example had wrong id labels. This should be right:

library(lattice)
x1 <- seq(-10, 10, 0.5)
x2 <- seq(-10, 10, 0.1)

df <- data.frame(x=x1, y=sin(x1), id='1a_s1', type='A', set='s1')
df <- rbind(df, data.frame(x=x1, y=cos(x1), id='1b_s1', type='B', set='s1'))
df <- rbind(df, data.frame(x=x1, y=3*sin(2*x1), id='2a_s1', type='A', set='s1'))
df <- rbind(df, data.frame(x=x1, y=3*cos(2*x1), id='2b_s1', type='B', set='s1'))

df <- rbind(df, data.frame(x=x2, y=sin(x2), id='1a_s2', type='A', set='s2'))
df <- rbind(df, data.frame(x=x2, y=cos(x2), id='1b_s2', type='B', set='s2'))
df <- rbind(df, data.frame(x=x2, y=3*sin(2*x2), id='2a_s2', type='A', set='s2'))
df <- rbind(df, data.frame(x=x2, y=3*cos(2*x2), id='2b_s2', type='B', set='s2'))

p=xyplot(y~x|set, df, type='l', group=type, auto.key = list(points =
FALSE, lines = TRUE, columns = 2))
print(p)

__
R-help@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.


Re: [R] Lattice xyplot and groups

2010-09-21 Thread Phil Spector

Does using

 df = df[order(df$type,df$set,df$x),]

before calling xyplot fix the problem?

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu




On Tue, 21 Sep 2010, Axel wrote:


Hi,

I'm trying to plot many (x, y) data files using the xyplot function
from the lattice package. Each file can be classified by set name (s1,
s2,...) and data type (A, B, ...). Each data set contains a different
number of files. If the data is grouped by type or set and visualized
as line plot with xyplot(type='l'), the first and last point are
joined into a closed line that traverses the whole plot from left to
right.
This is an example showing the problem:

library(lattice)
x1 <- seq(-10, 10, 0.5)
x2 <- seq(-10, 10, 0.1)

df <- data.frame(x=x1, y=sin(x1), id='1a_s1', type='A', set='s1')
df <- rbind(df, data.frame(x=x1, y=cos(x1), id='1b_s1', type='B', set='s1'))
df <- rbind(df, data.frame(x=x1, y=3*sin(2*x1), id='2a_s1', type='A', set='s1'))
df <- rbind(df, data.frame(x=x1, y=3*cos(2*x1), id='2b_s1', type='B', set='s1'))

df <- rbind(df, data.frame(x=x2, y=sin(x2), id='1a_s1', type='A', set='s2'))
df <- rbind(df, data.frame(x=x2, y=cos(x2), id='1b_s1', type='B', set='s2'))
df <- rbind(df, data.frame(x=x2, y=3*sin(2*x2), id='2a_s1', type='A', set='s2'))
df <- rbind(df, data.frame(x=x2, y=3*cos(2*x2), id='2b_s1', type='B', set='s2'))

p=xyplot(y~x|set, df, type='l', group=type, auto.key = list(points =
FALSE, lines = TRUE, columns = 2))
print(p)

I would really appreciate if you could suggest a way to keep the lines
open, either by changing the plot command or by building the data
frame in a better way. One solution would be to group by id, but then
I don't know if it is possible to make the line color the same for a
given data type.

Thank you!

__
R-help@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.



__
R-help@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.


[R] Lattice xyplot and groups

2010-09-21 Thread Axel
Hi,

I'm trying to plot many (x, y) data files using the xyplot function
from the lattice package. Each file can be classified by set name (s1,
s2,...) and data type (A, B, ...). Each data set contains a different
number of files. If the data is grouped by type or set and visualized
as line plot with xyplot(type='l'), the first and last point are
joined into a closed line that traverses the whole plot from left to
right.
This is an example showing the problem:

library(lattice)
x1 <- seq(-10, 10, 0.5)
x2 <- seq(-10, 10, 0.1)

df <- data.frame(x=x1, y=sin(x1), id='1a_s1', type='A', set='s1')
df <- rbind(df, data.frame(x=x1, y=cos(x1), id='1b_s1', type='B', set='s1'))
df <- rbind(df, data.frame(x=x1, y=3*sin(2*x1), id='2a_s1', type='A', set='s1'))
df <- rbind(df, data.frame(x=x1, y=3*cos(2*x1), id='2b_s1', type='B', set='s1'))

df <- rbind(df, data.frame(x=x2, y=sin(x2), id='1a_s1', type='A', set='s2'))
df <- rbind(df, data.frame(x=x2, y=cos(x2), id='1b_s1', type='B', set='s2'))
df <- rbind(df, data.frame(x=x2, y=3*sin(2*x2), id='2a_s1', type='A', set='s2'))
df <- rbind(df, data.frame(x=x2, y=3*cos(2*x2), id='2b_s1', type='B', set='s2'))

p=xyplot(y~x|set, df, type='l', group=type, auto.key = list(points =
FALSE, lines = TRUE, columns = 2))
print(p)

I would really appreciate if you could suggest a way to keep the lines
open, either by changing the plot command or by building the data
frame in a better way. One solution would be to group by id, but then
I don't know if it is possible to make the line color the same for a
given data type.

Thank you!

__
R-help@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.


Re: [R] lattice::xyplot() with one factor for points and another for lines - solution

2010-08-22 Thread Dennis Murphy
Hi:

Yesterday, I posted a question regarding how to handle different graphical
behavior between two factors in xyplot() [package lattice]. After a public
and private reply from Deepayan Sarkar, the problem has been resolved
nicely, including the addition of a stacked legend for the two factors in
question. The latter requires package latticeExtra.

library(lattice)
library(latticeExtra)

# Test data:
d <- data.frame(time = rep(1:8, each = 6), val = rnorm(48),
gp1 = factor(rep(1:6, 8)),
gp2 = factor(rep(rep(c('A', 'B'), each = 3), 8)))

mypch <- 1:6
mycol <- 1:6

# Define individual keys for each of the two factors
# Details on xyplot() help page

mykey1 <- list(title = 'Group 1',
   cex.title = 1.2,
  text = list(levels(d$gp1), cex = 0.8),
  points = list(pch = 1:6, col = 1:6), cex = 0.8)
mykey2 <- list(title = 'Group 2',
   cex.title = 1.2,
  text = list(levels(d$gp2)),
  lines = list(lty = 1, col = c('blue', 'orange')))

# Create a grob by merging the two keys - from latticeExtra (Felix Andrews)
mylegend <-
   mergedTrellisLegendGrob(list(fun = draw.key, args = list(key = mykey1)),
   list(fun = draw.key, args = list(key = mykey2)),
   vertical = TRUE)

# Generate the plot:
with(d,
xyplot(val ~ time,
   pch = mypch, col = mycol,
   lty = 1, col.line = c('blue', 'red'),
   subscripts = TRUE,
   panel = function(x, y, ..., groups) {
   panel.superpose(x, y, ..., groups = gp1, panel =
panel.points)
   panel.superpose(x, y, ..., groups = gp2, panel = panel.loess)
   },
   par.settings = list(layout.widths = list(key.right = 1.6)),
   legend = list(right = list(fun = mylegend

The panel function uses panel.superpose to separate the task of plotting
points according to the levels of gp1 from the task of producing loess fits
to the groups in gp2. In particular, panel.loess is not 'group aware', so
the panel.superpose code is necessary to plot loess smooths by group in this
context. Note the subscripts = TRUE argument *outside* of the panel function
so that the panel function can operate on the groups. The legend statement
uses mylegend as the argument to fun, where fun can either be a grob (which
mylegend happens to be here) or a function; in the latter case, the function
needs to be followed by args = list(...), where ... is a placeholder for the
assigned values of the function arguments. [See the call to
mergedTrellisLegendGrob(), for example.] Finally, par.settings is used in
this context to provide extra horizontal space on the right to comfortably
contain the legend contents.

Thanks to Deepayan for his lucid and informative replies. I hope this will
be of use to others.

Regards,
Dennis

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] lattice::xyplot() with one factor for points and another for lines

2010-08-21 Thread Deepayan Sarkar
On Sat, Aug 21, 2010 at 5:58 AM, Dennis Murphy  wrote:
> Hi:
>
> In lattice, how does one handle separate graphical behavior for two
> different factors? In the xyplot below, the objective is to use the levels
> of one factor to distinguish corresponding shapes and colors, and the levels
> of the other factor to perform level-wise loess smooths.
>
> # Illustrative data:
> d <- data.frame(time = rep(1:8, each = 6), val = rnorm(48),
>                gp1 = factor(rep(1:6, 8)),
>                gp2 = factor(rep(rep(c('A', 'B'), each = 3), 8)))
>
> Based on the code from the Lattice book, p. 160, I set up the following:
>
> mypch <- 1:6
> mycol <- 1:6
>
> with(d,
> xyplot(val ~ time,
>       panel = function(x, y, ..., groups, subscripts) {
>                 pch <- mypch[gp1[subscripts]]
>                 col <- mycol[gp1[subscripts]]
>                 grp <- gp2
>                 panel.xyplot(x, y, pch = pch, col = col)
>                 panel.loess(x, y, groups = grp, lty = 1,
>                             col.line = c('blue', 'red'))
>          }
>      )  )
>
> As stated in the book, the with() wrapper allows one to use variable names
> within the panel function. I was hoping to get away with using both groups
> and subscripts in the panel function and fake my way through, but no luck. I
> get 90% of what I want: the points are plotted correctly, but only one loess
> line shows up instead of two. I put groups before the ellipsis in the
> argument list, defined groups = gp2 in the function call and a couple of
> other things, but got the same result.

You are on the right track, except that panel.loess is not "groups-aware".

I would do something like

with(d,
 xyplot(val ~ time,
pch = mypch, col = mycol,
lty = 1, col.line = c('blue', 'red'),
subscripts = TRUE,
panel = function(x, y, ..., groups) {
panel.superpose(x, y, ..., groups = gp1, panel = panel.points)
panel.superpose(x, y, ..., groups = gp2, panel = panel.loess)
}))

The first call inside the panel function could be simpler, but this
makes the intention clearer.

-Deepayan

__
R-help@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.


[R] lattice::xyplot() with one factor for points and another for lines

2010-08-21 Thread Dennis Murphy
Hi:

In lattice, how does one handle separate graphical behavior for two
different factors? In the xyplot below, the objective is to use the levels
of one factor to distinguish corresponding shapes and colors, and the levels
of the other factor to perform level-wise loess smooths.

# Illustrative data:
d <- data.frame(time = rep(1:8, each = 6), val = rnorm(48),
gp1 = factor(rep(1:6, 8)),
gp2 = factor(rep(rep(c('A', 'B'), each = 3), 8)))

Based on the code from the Lattice book, p. 160, I set up the following:

mypch <- 1:6
mycol <- 1:6

with(d,
xyplot(val ~ time,
   panel = function(x, y, ..., groups, subscripts) {
 pch <- mypch[gp1[subscripts]]
 col <- mycol[gp1[subscripts]]
 grp <- gp2
 panel.xyplot(x, y, pch = pch, col = col)
 panel.loess(x, y, groups = grp, lty = 1,
 col.line = c('blue', 'red'))
  }
  )  )

As stated in the book, the with() wrapper allows one to use variable names
within the panel function. I was hoping to get away with using both groups
and subscripts in the panel function and fake my way through, but no luck. I
get 90% of what I want: the points are plotted correctly, but only one loess
line shows up instead of two. I put groups before the ellipsis in the
argument list, defined groups = gp2 in the function call and a couple of
other things, but got the same result.

I also tried to put the groups argument at the level of the xyplot() call,
but as expected, it plots only the points and skips the loess curves
altogether (but does tell you something about how the panel function
behaves):

# Vain, desperate, naive attempt:
with(d,
xyplot(val ~ time, groups = gp2, type = c('p', 'smooth'),
col.lines = c('red', 'blue'), lty = 1,
   panel = function(x, y, ..., groups = gp2, subscripts) {
 pch <- mypch[gp1[subscripts]]
 col <- mycol[gp1[subscripts]]
 panel.xyplot(x, y, pch = pch, col = col)
  } )   )

Adding panel.loess(x, y, groups = groups, ...) leaves the same single line.

What's the correct mantra? I'm probably missing something fairly obvious,
but it escapes me.  [And before Hadley chimes in, I already have a working
version in ggplot2, but the person I'm trying to help wants it in lattice,
too.]

TIA for your assistance,
Dennis

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] lattice xyplot with bty="l"

2010-07-07 Thread László Sándor
Thank you, this has been really helpful, I think I have managed to
produce the desired effect.

However, I am having trouble with generating and passing subscripts
from the main xyplot call to panel.superpose. My code resembles the
examples (e.g. pp 71-73) in your 2008 book --- though I cannot refer
to generic variable names "x", "y" or "groups" in panel (and panel.
functions) within xyplot either, so the problem need not be with
subscripts.

If you could have a look, I paste my entire function below to be
"almost functional," but the problem is relatively straightforward,
around the end in the panel call.

Thank you again,

Laszlo

scatter_contrast <- function(depvar,bins,cutvar,cutvarname = NULL,
yvarlab = NULL,xvarlab =
NULL,nbins=20,maxbins=100,yrange=c(0,9),plottitle=NULL,legendtitle=NULL)
 {
library('lattice')
library('grid')
trellis.par.set(
plot.symbol = list(cex = 1.5,col=rgb(26,71,111,max=255)),
superpose.symbol = list(cex = rep(1,
times=7),pch=c(15:21),col=c(rgb(26,71,111,max=255),
rgb(144,53,59,max=255),rgb(85,117,47,max=255),"#ff","orange","#00ff00","brown"),fill=c(rgb(26,71,111,max=255),
  
rgb(144,53,59,max=255),rgb(85,117,47,max=255),"#ff","orange","#00ff00","brown")),
plot.line = list(cex = 1,lwd=2,col=rgb(26,71,111,max=255)),
superpose.line = list(cex = rep(1,
times=7),lwd=rep(2,times=7),col=c(rgb(26,71,111,max=255),
rgb(144,53,59,max=255),rgb(85,117,47,max=255),"#ff","orange","#00ff00","brown")),
reference.line = list(col=rgb(234,242,243,max=255)),
add.line = list(rgb(85,117,47,max=255),lwd=2),
grid.pars = list(col="black"),#rgb(234,242,243,max=255)),
superpose.polygon = 
list(col="black"),#rgb(234,242,243,max=255)),
fontsize = list(text=16),   
par.xlab.text = list(cex = 0.8),
par.ylab.text = list(cex = 0.8),
)
if (length(unique(bins))>maxbins) bins <- binning(bins,nbins)
temp <- summary(cutvar)
cut <- 1*(cutvar > temp[3])
if (length(unique(!is.na(cutvar)))<6) cut <- cutvar
legval1 <- names(data.frame(cutvar))
xl <- names(data.frame(bins))
leg <- paste(unique(sort(cut)))
legval2 <- leg[1:(length(unique(leg))-1)]
if (length(na.omit(cutvar)) == length(cutvar)) legval2 <- leg
ht <- depvar[[1]]
if (is.na(ht)) ht <- 0
if (ht == "hist") {
bins <- 
replace(bins,bins>quantile(bins,0.99),quantile(bins,0.99))
bins <- 
replace(bins,bins:
> 2010/7/5 László Sándor :
>> Hi all,
>>
>> Back in 2007, Deepayan and Patrick had an exchange about how to modify
>> axes for lattice plots (pasted below). I need something similar, but I
>> also need to produce ticks on the axes. Deepayan quickly coded up
>> substitute gridlines because they needed to make the default box
>> transparent. The code works, but it lacks the ticks, and I could not
>> google up how to add them.
>>
>> (I would be taken aback if you could even help me but this option into
>> a theme for the latticeExtra package -- the grid options there do not
>> seem to allow left and bottom axes at the same time. Not even
>> asTheEconomist command, though I thought I have seen plot with
>> "bty="l" " in The Economist...)
>>
>> I understand that panels in lattice were not intended for such use
>> originally, but for many advanced features of the lattice package, my
>> team wants to use this. The specific goal would be to produce graphs
>> in R like those here:
>> http://obs.rc.fas.harvard.edu/chetty/denmark_adjcost_slides.pdf  .
>>
>> Any help would be greatly appreciated.
>
> The first step would be
>
> xyplot(1:10 ~ 1:10, par.settings=list(axis.line = list(col = "transparent")),
>        scales = list(col = "black", tck = c(1, 0)))
>
> You can then add the sides in the panel function (or axis function).
>
> -Deepayan
>

__
R-help@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.


Re: [R] lattice xyplot with bty="l"

2010-07-07 Thread Deepayan Sarkar
2010/7/5 László Sándor :
> Hi all,
>
> Back in 2007, Deepayan and Patrick had an exchange about how to modify
> axes for lattice plots (pasted below). I need something similar, but I
> also need to produce ticks on the axes. Deepayan quickly coded up
> substitute gridlines because they needed to make the default box
> transparent. The code works, but it lacks the ticks, and I could not
> google up how to add them.
>
> (I would be taken aback if you could even help me but this option into
> a theme for the latticeExtra package -- the grid options there do not
> seem to allow left and bottom axes at the same time. Not even
> asTheEconomist command, though I thought I have seen plot with
> "bty="l" " in The Economist...)
>
> I understand that panels in lattice were not intended for such use
> originally, but for many advanced features of the lattice package, my
> team wants to use this. The specific goal would be to produce graphs
> in R like those here:
> http://obs.rc.fas.harvard.edu/chetty/denmark_adjcost_slides.pdf  .
>
> Any help would be greatly appreciated.

The first step would be

xyplot(1:10 ~ 1:10, par.settings=list(axis.line = list(col = "transparent")),
scales = list(col = "black", tck = c(1, 0)))

You can then add the sides in the panel function (or axis function).

-Deepayan

__
R-help@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.


Re: [R] lattice xyplot with bty="l"

2010-07-05 Thread László Sándor
Hi all,

Back in 2007, Deepayan and Patrick had an exchange about how to modify
axes for lattice plots (pasted below). I need something similar, but I
also need to produce ticks on the axes. Deepayan quickly coded up
substitute gridlines because they needed to make the default box
transparent. The code works, but it lacks the ticks, and I could not
google up how to add them.

(I would be taken aback if you could even help me but this option into
a theme for the latticeExtra package -- the grid options there do not
seem to allow left and bottom axes at the same time. Not even
asTheEconomist command, though I thought I have seen plot with
"bty="l" " in The Economist...)

I understand that panels in lattice were not intended for such use
originally, but for many advanced features of the lattice package, my
team wants to use this. The specific goal would be to produce graphs
in R like those here:
http://obs.rc.fas.harvard.edu/chetty/denmark_adjcost_slides.pdf  .

Any help would be greatly appreciated.

Thank you very much,

Laszlo

László Sándor
graduate student
Department of Economics
Harvard University

"Deepayan Sarkar" <[EMAIL PROTECTED]> writes:

> On 9/4/07, Patrick Drechsler <[EMAIL PROTECTED]> wrote:
>>
>> what is the correct way of removing the "top" and "right" axes
>> completely from a lattice xyplot? I would like to have a plot similar
>> to using the bty="l" option for traditional plots.
>
> There is no direct analog (and I think it would be weird in a
> multipanel plot).

I agree that this is not very useful for multipanel plots.

> Combining a few different features, you can do:
>
> library(grid)
>
> xyplot(1:10 ~ 1:10, scales = list(col = "black", tck = c(1, 0)),
>par.settings = list(axis.line = list(col = "transparent")),
>axis = function(side, ...) {
>if (side == "left")
> grid.lines(x = c(0, 0), y = c(0, 1),
>default.units = "npc")
>else if (side == "bottom")
> grid.lines(x = c(0, 1), y = c(0, 0),
>default.units = "npc")
>axis.default(side = side, ...)
>})
>
> -Deepayan

Thank you very much Deepayan, this is exactly what I was looking for!

Cheers,

Patrick

__
R-help@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.


Re: [R] lattice, xyplot, using "panel.segments" by just addressing one panel

2010-06-02 Thread Peter Ehlers

Doris,

You might get lucky and find some kind soul who's willing to
dig through your *un*reproducible code, but your chances for
help would probably increase dramatically if you were to
provide *reproducible* and *minimal* code to illustrate your
problem. I imagine that you might benefit from reading the
posting guide.

It may be that trellis.focus() solves your problem.

 -Peter Ehlers

On 2010-06-02 8:46, Doris wrote:


Hi R experts,

I'm using the xyplot function in lattice to draw a multipanel plot consiting
of 5x6 scatterplots.
Now I need to link single points in each of those scatterplots (=panel),but
the points, that need linking are different for each panel.
I tried to use the panel.segments function for that, but I can't address
each panel separately. Links right for panel 1, show up in all other panels,
too. Tried functions like [panel.number()], but didn't work.

Would be so great, if somebody could help me with that!

That's the code, I used:

library(lattice)
library(latticeExtra)
#[...]
attach(mydata)
attach(links)  #containing the coordinates for the segments fx, fy, tx, ty

fx<- fx
fy<- fy
tx<- tx
ty<- ty

xyplot(LogN~LogM|factor(surber),
par.settings = list(strip.background = list(col = "transparent")),
xlab = "Log M", ylab = "Log N",
layout = c(6,5), aspect = 1, as.table = TRUE, strip=FALSE,
panel=function(x,y){
panel.xyplot(x,y,pch=20,col="black", bg="transparent")
panel.fill(col = "transparent")
panel.segments(fx,fy,tx,ty[panel.number()])

})


Also tried to split the data and loop it (but this code might be a bit
messy. Apologies!) sn is the variable used to split according to panel. I
just tried to do the links for 2 panel here:

fx<- split(links$fx,links$sn)
fy<- split(links$fy,links$sn)
tx<- split(links$tx,links$sn)
ty<- split(links$ty,links$sn)
sn<- sn
dothese<- c(1,2)
ct<- 0
for (i in dothese){
ct<- ct + 1
x1<- fx[[i]]
y1<- fy[[i]]
x2<- tx[[i]]
y2<- ty[[i]]
}


xyplot(LogN~LogM|factor(surber),
par.settings = list(strip.background = list(col = "transparent")),
xlab = "Log M", ylab = "Log N",
layout = c(6,5), aspect = 1, as.table = TRUE, strip=FALSE,
panel=function(x,y){
panel.xyplot(x,y,pch=20,col="black", bg="transparent")
panel.fill(col = "transparent")
panel.segments (x1,y1,x2,y2 [panel.number(1,2)])

})



Thanks, Doris


__
R-help@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.


[R] lattice, xyplot, using "panel.segments" by just addressing one panel

2010-06-02 Thread Doris

Hi R experts, 

I'm using the xyplot function in lattice to draw a multipanel plot consiting
of 5x6 scatterplots.
Now I need to link single points in each of those scatterplots (=panel),but
the points, that need linking are different for each panel.
I tried to use the panel.segments function for that, but I can't address
each panel separately. Links right for panel 1, show up in all other panels,
too. Tried functions like [panel.number()], but didn't work. 

Would be so great, if somebody could help me with that!

That's the code, I used:

library(lattice)
library(latticeExtra)
#[...]
attach(mydata)
attach(links)  #containing the coordinates for the segments fx, fy, tx, ty

fx <- fx
fy <- fy
tx <- tx
ty <- ty

xyplot(LogN~LogM|factor(surber),
par.settings = list(strip.background = list(col = "transparent")),
xlab = "Log M", ylab = "Log N",  
layout = c(6,5), aspect = 1, as.table = TRUE, strip=FALSE,
panel=function(x,y){
panel.xyplot(x,y,pch=20,col="black", bg="transparent")
panel.fill(col = "transparent")
panel.segments(fx,fy,tx,ty[panel.number()])

})


Also tried to split the data and loop it (but this code might be a bit
messy. Apologies!) sn is the variable used to split according to panel. I
just tried to do the links for 2 panel here:

fx <- split(links$fx,links$sn)
fy <- split(links$fy,links$sn)
tx <- split(links$tx,links$sn)
ty <- split(links$ty,links$sn)
sn <- sn
dothese <- c(1,2) 
ct <- 0 
for (i in dothese){
ct <- ct + 1 
x1 <- fx[[i]]
y1 <- fy[[i]]
x2 <- tx[[i]]
y2 <- ty[[i]]
}


xyplot(LogN~LogM|factor(surber),
par.settings = list(strip.background = list(col = "transparent")),
xlab = "Log M", ylab = "Log N",  
layout = c(6,5), aspect = 1, as.table = TRUE, strip=FALSE, 
panel=function(x,y){
panel.xyplot(x,y,pch=20,col="black", bg="transparent")
panel.fill(col = "transparent")
panel.segments (x1,y1,x2,y2 [panel.number(1,2)])

})



Thanks, Doris


-- 
View this message in context: 
http://r.789695.n4.nabble.com/lattice-xyplot-using-panel-segments-by-just-addressing-one-panel-tp2240248p2240248.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] lattice xyplot strip colors and location

2009-10-19 Thread ShankarAjay

Hi Duncan, 

Thanks for your response and I'm sorry for the delayed reply - think my spam
filter is to blame. 
Your solution did work. Thanks a ton!

Shankar


Duncan Mackay-2 wrote:
> 
> Hi Shankar
> 
> On a slightly different note - below produces a strip to the left without 
> the stacked strips
> 
> require(latticeExtra) # NB install if not found
> 
> useOuterStrips(strip=strip.custom(bg="skyblue"),
> strip.left=strip.custom(bg="yellow"),
> xyplot(V4~V3|frac.f*stdev.f,
> aspect=3/4,
> xlab="Min number of reads",
> ylab="Number of misjoins"
> )
> )
> 
> 
> 
> HTH
> 
> Duncan Mackay
> Department of Agronomy and Soil Science
> Univeristy of New England
> ARMIDALE NSW 2351
> Email: home : mac...@northnet.com.au
> 
> 
> At 12:23 20/08/2009, you wrote:
>>Hi all,
>>
>>I've been trying (unsuccessfully) to modify an xyplot I created using the 
>>lattice package. I would like to change default strip colors and
locations.
>>I started with numeric data in 4 columns, which look like this:
>>
>>0.252   1   32
>>0.252   2   30
>>0.252   3   27
>>0.252   4   23
>>0.252   5   17
>>0.253   1   30
>>0.253   2   29
>>0.253   3   26
>>0.253   4   21
>>0.253   5   15
>>0.5 2   1   23
>>0.5 2   2   23
>>0.5 2   3   22
>>0.5 2   4   18
>>0.5 2   5   15
>>0.5 3   1   22
>>0.5 3   2   22
>>0.5 3   3   21
>>0.5 3   4   16
>>0.5 3   5   13
>>
>>Here's what I've done so far:
>>
>>library(lattice)
>>plotdata <- read.table(file="data.txt", header=FALSE)
>>
>>attach(plotdata)
>>
>>frac.f <- factor(V1)
>>stdev.f <- factor(V2)
>>levels(frac.f) <- paste("f=",levels(frac.f), sep="")
>>levels(stdev.f) <- paste("s=", levels(stdev.f), sep="")
>>xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab="Reads as evidence", 
>>ylab="Total incorrect")
>>detach(plotdata)
>>
>>Conditional variable values now appear as two stacked strips at the top of 
>>each panel. I'd like to move one to the left and also change strip colors.
>>
>>I tried the following but it didn't produce the desired result
>>
>>xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab="Min number of reads", 
>>ylab="Number of misjoins", strip=strip.custom(which.given=1, 
>>bg="skyblue"), strip.left=strip.custom(which.given=2,bg="yellow"))
>>
>>This changes the colors but also does the following
>>- positions the left strips slightly away from the respective panels
>>- all strip labels and values reflect only one conditional variable (s=2, 
>>s=3, etc.)
>>
>>Any help would be much appreciated
>>
>>Thanks,
>>Shankar
>>
>>Postdoctoral Fellow
>>National Human Genome Research Institute
>>NIH
>>Bethesda, MD
>>__
>>R-help@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.
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/lattice-xyplot-strip-colors-and-location-tp25055871p25968621.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Lattice xyplot: modify line width of plot lines

2009-08-24 Thread ukoenig

Now it works.
Many thanks, Chuck!



Quoting Chuck Cleland :


On 8/24/2009 4:47 AM, ukoe...@med.uni-marburg.de wrote:

# Hi all,
# I want to increase the line width of the plotted lines
# in a xy-lattice plot. My own attempts were all in vain.
# Without the group option the line width is modified -
# with the option it is funnily enough not.
# Please have a look at my syntax.
#
# Many thanks in advance
# Udo


  You need to change the superpose.line setting:

xyplot(Choline ~ time,
   groups=BMI,
   data=data,
   type="l",
   scales=list(relation="free"),
   auto.key=list(title="BMI Group",
 border=FALSE, lines=TRUE, points=FALSE),
   xlab=c("Point in Time"),
   ylab=c("Concentration of Choline"),
   par.settings = list(superpose.line = list(lwd=3)))




library(lattice)

data <- data.frame(cbind(1:2,c(1,1,2,2), c(0.5,0.9,1.0,1.8)))
names(data) <- c("BMI","time","Choline")

data$BMI <- factor(data$BMI)
levels(data$BMI) <- c("<=17.5",">17.5")
data$time <- factor(data$time)
levels(data$time) <- c("Admission","Discharge")


#Show names of settings
names(trellis.par.get())

#Try to set the line width of the two plotted colored lines
line<-trellis.par.get("plot.line")
line
line$lwd=3
trellis.par.set("plot.line", line)
line


#Without group option: Line width is changed
xyplot(Choline ~ time,
   data=data,
   type="l",
   scales=list(relation="free"),
   auto.key=list(title="BMI Group", border=FALSE),
   xlab=c("Point in Time"),
   ylab=c("Concentration of Choline"))

#With group option: Line width is not changed
xyplot(Choline ~ time,
   group=BMI,
   data=data,
   type="l",
   scales=list(relation="free"),
   auto.key=list(title="BMI Group", border=FALSE),
   xlab=c("Point in Time"),
   ylab=c("Concentration of Choline"))

__
R-help@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.




--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



__
R-help@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.


Re: [R] Lattice xyplot: modify line width of plot lines

2009-08-24 Thread Chuck Cleland
On 8/24/2009 4:47 AM, ukoe...@med.uni-marburg.de wrote:
> # Hi all,
> # I want to increase the line width of the plotted lines
> # in a xy-lattice plot. My own attempts were all in vain.
> # Without the group option the line width is modified -
> # with the option it is funnily enough not.
> # Please have a look at my syntax.
> #
> # Many thanks in advance
> # Udo

  You need to change the superpose.line setting:

xyplot(Choline ~ time,
   groups=BMI,
   data=data,
   type="l",
   scales=list(relation="free"),
   auto.key=list(title="BMI Group",
 border=FALSE, lines=TRUE, points=FALSE),
   xlab=c("Point in Time"),
   ylab=c("Concentration of Choline"),
   par.settings = list(superpose.line = list(lwd=3)))

> 
> 
> library(lattice)
> 
> data <- data.frame(cbind(1:2,c(1,1,2,2), c(0.5,0.9,1.0,1.8)))
> names(data) <- c("BMI","time","Choline")
> 
> data$BMI <- factor(data$BMI)
> levels(data$BMI) <- c("<=17.5",">17.5")
> data$time <- factor(data$time)
> levels(data$time) <- c("Admission","Discharge")
> 
> 
> #Show names of settings
> names(trellis.par.get())
> 
> #Try to set the line width of the two plotted colored lines
> line<-trellis.par.get("plot.line")
> line
> line$lwd=3
> trellis.par.set("plot.line", line)
> line
> 
> 
> #Without group option: Line width is changed
> xyplot(Choline ~ time,
>data=data,
>type="l",
>scales=list(relation="free"),
>auto.key=list(title="BMI Group", border=FALSE),
>xlab=c("Point in Time"),
>ylab=c("Concentration of Choline"))
> 
> #With group option: Line width is not changed
> xyplot(Choline ~ time,
>group=BMI,
>data=data,
>type="l",
>scales=list(relation="free"),
>auto.key=list(title="BMI Group", border=FALSE),
>xlab=c("Point in Time"),
>ylab=c("Concentration of Choline"))
> 
> __
> R-help@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.
> 


-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@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.


[R] Lattice xyplot: modify line width of plot lines

2009-08-24 Thread ukoenig

# Hi all,
# I want to increase the line width of the plotted lines
# in a xy-lattice plot. My own attempts were all in vain.
# Without the group option the line width is modified -
# with the option it is funnily enough not.
# Please have a look at my syntax.
#
# Many thanks in advance
# Udo




library(lattice)

data <- data.frame(cbind(1:2,c(1,1,2,2), c(0.5,0.9,1.0,1.8)))
names(data) <- c("BMI","time","Choline")

data$BMI <- factor(data$BMI)
levels(data$BMI) <- c("<=17.5",">17.5")
data$time <- factor(data$time)
levels(data$time) <- c("Admission","Discharge")


#Show names of settings
names(trellis.par.get())

#Try to set the line width of the two plotted colored lines
line<-trellis.par.get("plot.line")
line
line$lwd=3
trellis.par.set("plot.line", line)
line


#Without group option: Line width is changed
xyplot(Choline ~ time,
   data=data,
   type="l",
   scales=list(relation="free"),
   auto.key=list(title="BMI Group", border=FALSE),
   xlab=c("Point in Time"),
   ylab=c("Concentration of Choline"))

#With group option: Line width is not changed
xyplot(Choline ~ time,
   group=BMI,
   data=data,
   type="l",
   scales=list(relation="free"),
   auto.key=list(title="BMI Group", border=FALSE),
   xlab=c("Point in Time"),
   ylab=c("Concentration of Choline"))

__
R-help@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.


Re: [R] lattice xyplot strip colors and location

2009-08-20 Thread Duncan Mackay

Hi Shankar

On a slightly different note - below produces a strip to the left without 
the stacked strips


require(latticeExtra) # NB install if not found

useOuterStrips(strip=strip.custom(bg="skyblue"),
   strip.left=strip.custom(bg="yellow"),
xyplot(V4~V3|frac.f*stdev.f,
   aspect=3/4,
   xlab="Min number of reads",
   ylab="Number of misjoins"
   )
)



HTH

Duncan Mackay
Department of Agronomy and Soil Science
Univeristy of New England
ARMIDALE NSW 2351
Email: home : mac...@northnet.com.au


At 12:23 20/08/2009, you wrote:

Hi all,

I've been trying (unsuccessfully) to modify an xyplot I created using the 
lattice package. I would like to change default strip colors and locations.

I started with numeric data in 4 columns, which look like this:

0.252   1   32
0.252   2   30
0.252   3   27
0.252   4   23
0.252   5   17
0.253   1   30
0.253   2   29
0.253   3   26
0.253   4   21
0.253   5   15
0.5 2   1   23
0.5 2   2   23
0.5 2   3   22
0.5 2   4   18
0.5 2   5   15
0.5 3   1   22
0.5 3   2   22
0.5 3   3   21
0.5 3   4   16
0.5 3   5   13

Here's what I've done so far:

library(lattice)
plotdata <- read.table(file="data.txt", header=FALSE)

attach(plotdata)

frac.f <- factor(V1)
stdev.f <- factor(V2)
levels(frac.f) <- paste("f=",levels(frac.f), sep="")
levels(stdev.f) <- paste("s=", levels(stdev.f), sep="")
xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab="Reads as evidence", 
ylab="Total incorrect")

detach(plotdata)

Conditional variable values now appear as two stacked strips at the top of 
each panel. I'd like to move one to the left and also change strip colors.


I tried the following but it didn't produce the desired result

xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab="Min number of reads", 
ylab="Number of misjoins", strip=strip.custom(which.given=1, 
bg="skyblue"), strip.left=strip.custom(which.given=2,bg="yellow"))


This changes the colors but also does the following
- positions the left strips slightly away from the respective panels
- all strip labels and values reflect only one conditional variable (s=2, 
s=3, etc.)


Any help would be much appreciated

Thanks,
Shankar

Postdoctoral Fellow
National Human Genome Research Institute
NIH
Bethesda, MD
__
R-help@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.


__
R-help@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.


[R] lattice xyplot strip colors and location

2009-08-19 Thread Ajay, Shankar Ajay (NIH/NHGRI) [F]
Hi all, 

I've been trying (unsuccessfully) to modify an xyplot I created using the 
lattice package. I would like to change default strip colors and locations. 
I started with numeric data in 4 columns, which look like this:

0.252   1   32
0.252   2   30
0.252   3   27
0.252   4   23
0.252   5   17
0.253   1   30
0.253   2   29
0.253   3   26
0.253   4   21
0.253   5   15
0.5 2   1   23
0.5 2   2   23
0.5 2   3   22
0.5 2   4   18
0.5 2   5   15
0.5 3   1   22
0.5 3   2   22
0.5 3   3   21
0.5 3   4   16
0.5 3   5   13

Here's what I've done so far:

library(lattice)
plotdata <- read.table(file="data.txt", header=FALSE)

attach(plotdata)

frac.f <- factor(V1)
stdev.f <- factor(V2)
levels(frac.f) <- paste("f=",levels(frac.f), sep="")
levels(stdev.f) <- paste("s=", levels(stdev.f), sep="")
xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab="Reads as evidence", ylab="Total 
incorrect")
detach(plotdata)

Conditional variable values now appear as two stacked strips at the top of each 
panel. I'd like to move one to the left and also change strip colors.

I tried the following but it didn't produce the desired result

xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab="Min number of reads", 
ylab="Number of misjoins", strip=strip.custom(which.given=1, bg="skyblue"), 
strip.left=strip.custom(which.given=2,bg="yellow"))

This changes the colors but also does the following 
- positions the left strips slightly away from the respective panels
- all strip labels and values reflect only one conditional variable (s=2, s=3, 
etc.)

Any help would be much appreciated

Thanks,
Shankar

Postdoctoral Fellow
National Human Genome Research Institute
NIH 
Bethesda, MD
__
R-help@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.


Re: [R] Lattice xyplot: same scales within one factor

2009-08-03 Thread OB
Thank you! I ended up hunting down a few previous posts you made and getting
it to to work, although yes, it was not pretty.

-Orion

On 8/3/09 10:30 am, "Deepayan Sarkar"  wrote:

> On Mon, Jul 13, 2009 at 8:33 AM, OB wrote:
>> I am using R 2.8.1 and lattice to produce xyplots conditioned on
>> two factors. What I would like is to have the scales be free between values
>> of one factor, but some within. Thus, in this example,
>> 
>> xyplot(mpg ~ disp | factor(gear) + factor(cyl), mtcars,
>>     scales=list(x=list(relation="free")))
>> 
>> rather than having the x scales be free within a gear as well, I want it to
>> be the same for the gear, but free between cyl (and thus only have x scales
>> below the bottom panels with no scales or white space in the middle between
>> panels).
> 
> Per-variable scales are not supported by lattice. You can sort of fake
> it by providing explicit limits and playing around with spacing, but
> it's fairly ugly.
> 
> -Deepayan

__
R-help@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.


  1   2   >