On Mon, Feb 13, 2023 at 3:48 AM Laurent Rhelp wrote:
>
> Dear R-Help-list,
>
> I want to use the doubleYScale function from latticeExtra to overlap two
> lattice graphs (cf. code below). The overlapping works but I lose the
> groups of
> every lattice, there are only two colors. Reading the documentation,
> the arguments style1 and style2 give me the impression that it is not
> possible to keep the groups of every lattice.
I'm mostly guessing from looking at the examples, but is this what you want?
gr_Gx_Tx <- latticeExtra::doubleYScale(gr_Gx, gr_Tx, style1 = 0, style2 = 0)
Best,
-Deepayan
> Is there any possibility to keep the groups of every lattice graph with
> the doubleYScale function ?
>
> Or, might you give me some orientations to realize the graph keeping the
> groups using the lattice package ?
>
> Thank you
>
> Best regards
>
> Laurent
>
> #-o<-->o-
> library(lattice)
> library(latticeExtra)
> ##
> ## creation of the first lattice graph gr_Gx with a group of two elements
> ##
> lattice.par <- trellis.par.get()
> my.superpose.line <- lattice.par$superpose.line
> my.superpose.line$col[1:2] <- c("black","red")
> gr_Gx <- xyplot( value ~ time | region
>, data = df.m
>, subset = sensor %in% c("G2","G4")
>, group = sensor
>, type ="l"
>, scales = list( y = list(log=10)
> , x = list(relation="free", axs =
> "i", abbreviate=TRUE))
>, yscale.components = yscale.components.log10ticks
>, par.settings = list(
> superpose.line = my.superpose.line
>)
> )
> print(gr_Gx)
> ##
> ## creation of the second lattice graph gr_Tx with a group of five elements
> ##
> lattice.par <- trellis.par.get()
> my.superpose.line <- lattice.par$superpose.line
> my.superpose.line$col[1:5] <- c(1,2,3,4,5)
> gr_Tx <- xyplot( value ~ time | region
> , group = sensor
> , subset = sensor %in% c("T1","T2","T3","T4","T5")
> , data= df.m
> , type = "l"
> , scales = list( x= list( axs = "i", relation = "free"
> , abbreviate = TRUE))
> , par.settings = list( superpose.line =
> my.superpose.line )
> )
> print(gr_Tx)
> ##
> ## overlap the two lattice graphs
> ## We lost the groups of every lattice
> ##
> gr_Gx_Tx <- latticeExtra::doubleYScale(gr_Gx, gr_Tx)
> print(gr_Gx_Tx)
>
> #o<-->o-
>
> The data :
>
> df.m <- structure(list(time = c(0.000250101089477539, 0.000250101089477539,
> 0.000250101089477539, 0.000250101089477539, 0.000250101089477539,
> 0.000250101089477539, 0.000250101089477539, 0.000500202178955078,
> 0.000500202178955078, 0.000500202178955078, 0.000500202178955078,
> 0.000500202178955078, 0.000500202178955078, 0.000500202178955078,
> 0.000750064849853516, 0.000750064849853516, 0.000750064849853516,
> 0.000750064849853516, 0.000750064849853516, 0.000750064849853516,
> 0.000750064849853516, 0.00100016593933105, 0.00100016593933105,
> 0.00100016593933105, 0.00100016593933105, 0.00100016593933105,
> 0.00100016593933105, 0.00100016593933105, 0.00125002861022949,
> 0.00125002861022949, 0.00125002861022949, 0.00125002861022949,
> 0.00125002861022949, 0.00125002861022949, 0.00125002861022949,
> 0.00150012969970703, 0.00150012969970703, 0.00150012969970703,
> 0.00150012969970703, 0.00150012969970703, 0.00150012969970703,
> 0.00150012969970703, 0.00175023078918457, 0.00175023078918457,
> 0.00175023078918457, 0.00175023078918457, 0.00175023078918457,
> 0.00175023078918457, 0.00175023078918457, 0.0029346008301,
> 0.0029346008301, 0.0029346008301, 0.0029346008301,
> 0.0029346008301, 0.0029346008301, 0.0029346008301,
> 0.00225019454956055, 0.00225019454956055, 0.00225019454956055,
> 0.00225019454956055, 0.00225019454956055, 0.00225019454956055,
> 0.00225019454956055, 0.00250005722045898, 0.00250005722045898,
> 0.00250005722045898, 0.00250005722045898, 0.00250005722045898,
> 0.00250005722045898, 0.00250005722045898, 0.00275015830993652,
> 0.00275015830993652, 0.00275015830993652, 0.00275015830993652,
> 0.00275015830993652, 0.00275015830993652, 0.00275015830993652,
> 0.0032098083496, 0.0032098083496, 0.0032098083496,
> 0.0032098083496, 0.0032098083496, 0.0032098083496,
> 0.0032098083496, 0.0032501220703125, 0.0032501220703125,
> 0.0032501220703125, 0.0032501220703125, 0.0032501220703125,
> 0.0032501220703125,
> 0.0032501220703125, 0.00350022315979004, 0.00350022315979004,
> 0.00350022315979004, 0.00350022315979004, 0.00350022315979004,
>