[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
Laurent Rhelp
L@urentRHe|p @end|ng |rom |ree@|r
Mon May 29 21:08:55 CEST 2023
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.479222240948,
-0.00833297732602559, -0.0452567494314687, -0.345867818702583,
-0.445302124137744, 0.0740098049592515, 0.00668399483148732,
161.820662102699, -172.786724020131, -79.0099113997788,
-0.00968888576618169,
-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,
0.000686413706888711,
-0.000344515127770701, 161.842017046496, -172.786724021693,
-78.1988044760812,
-0.00919251140327542, -0.0459506772930563, 0.0713228135448341,
0.956135146179378, -0.0445597374382429, -0.0135164266098543,
161.882810755159, -172.786724023696, -78.4976336446972,
-0.0104939151424264,
-0.0456232800083461, 0.833386283667222, 1.81495845695508,
-0.0772681391674729,
-0.0137590717147878, 161.961115481969, -172.786724019426, -78.946554213126,
-0.00914662536742281, -0.0453809447003485, 0.566770694646079,
-0.0824899290286683, -0.0826728987113129, -0.00757939062471868,
162.057012435199, -172.786724024379, -79.4665385064047,
-0.00880734063865791,
-0.0463440065912256, -0.269806552714627, -1.4786975633428,
-0.0683765844774749
)), row.names = c(NA, -100L), class = "data.frame")
## yscale.components.subticks customization
my_yscale.components.subticks <- function (lim, ..., n = 5, n2 = n * 5,
min.n2 = n + 5)
{
ans <- yscale.components.default(lim = lim, ..., n = n)
ans2 <- yscale.components.default(lim = lim, ..., n = n2,
min.n = min.n2)
ticks <- ans$left$ticks$at
ticks2 <- ans2$left$ticks$at
ticks2 <- ticks2[!(ticks2 %in% ticks)]
ans$left$ticks$at <- c(ticks, ticks2)
ans$left$ticks$tck <- c(rep(1, length(ticks)), rep(0.5, length(ticks2)))
ans$left$labels$at <- ans$left$ticks$at
ans$left$labels$labels <- c(ans$left$labels$labels, rep(" ",
length(ticks2)))
ans$left$labels$cex <- 0.3
ans$left$labels$check.overlap <- FALSE
## for test
## print(ans)
## ans$right <- TRUE
ans
}
dev.new()
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)
, scale = list( y = list( relation="free", draw=FALSE
, cex = 0.3)
, x = list( relation = "same", axs = "i"
, rot = 45, cex = 0.3))
, type=c("l","g")
, axis = function(side, ...) {
if (side == "right")
panel.axis(side = "right", outside = TRUE)
else axis.default(side = side, ...)
}
, 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)
)
)
print(gr)
----o<------------------------------------------>o---------
--
Cet e-mail a été vérifié par le logiciel antivirus d'Avast.
www.avast.com
More information about the R-help
mailing list