Force to show all labels in axis

 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)  

}

  

# The solution is in axis: gap.axis = -1

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"), gap.axis = -1, cex.axis=0.8)



Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

Install treemix in ubuntu 20.04

Multivariable analysis and correlation of iconography