[R] Only one label from axis() is shown

Marc Girondot m@rc_grt @end|ng |rom y@hoo@|r
Wed May 28 23:26:36 CEST 2025


Can someone explain me why in the second example, only one label is shown ?

Thanks a lot

Marc

atT <- structure(c(1672520400, 1675198800, 1677618000, 1680296400, 
1682888400,
             1685566800, 1688158800, 1690837200, 1693515600, 1696107600, 
1698786000,
             1701378000, 1704056400, 1706734800, 1709240400, 1711918800, 
1714510800,
             1717189200, 1719781200, 1722459600, 1725138000, 1727730000, 
1730408400,
             1733000400, 1735678800), class = c("POSIXct", "POSIXt"), 
tzone = "Asia/Riyadh")

# Work as expected
plot(x = atT, y=rep(1, length(atT)), xaxt="n")
axis(side = 1, at=atT, labels = as.character(seq_along(atT)))

# Only first label is shown
plot(x = atT, y=rep(1, length(atT)), xaxt="n")
axis(1, at=atT, label=c("Jan-2023", "", "", "", "", "", "Jul-2023", "", 
"", "", "", "",
                                     "Jan-2024", "", "", "", "", "", 
"Jul-2024", "", "", "", "", "",
                                     "Jan-2025"), cex.axis=0.8)

# All labels are shown... but not elegant !
plot(x = atT, y=rep(1, length(atT)), xaxt="n")
for (i in seq_along(atT)) {
   axis(1, at=atT[i], label=c("Jan-2023", "", "", "", "", "", 
"Jul-2023", "", "", "", "", "",
                           "Jan-2024", "", "", "", "", "", "Jul-2024", 
"", "", "", "", "",
                           "Jan-2025")[i], cex.axis=0.8)

}

 > R.version
                _
platform       aarch64-apple-darwin20
arch           aarch64
os             darwin20
system         aarch64, darwin20
status         Patched
major          4
minor          5.0
year           2025
month          05
day            16
svn rev        88216
language       R
version.string R version 4.5.0 Patched (2025-05-16 r88216)
nickname       How About a Twenty-Six

------------------------------------------------------------------------
*Marc Girondot, Pr*

Laboratoire Ecologie, Société, Evolution
Equipe de Processus Ecologiques et Pressions Anthropiques
CNRS, AgroParisTech et Université Paris-Saclay, UMR 8079
91190 Gif-sur-Yvette, France

Tel: +33 (0)1.69.15.72.30 Mobile: +33 (0)6.20.18.22.16
e-mail: marc.girondot using universite-paris-saclay.fr
marc.girondot using gmail.com

Web: http://hebergement.universite-paris-saclay.fr/marcgirondot/

	[[alternative HTML version deleted]]



More information about the R-help mailing list