Skip to content
Prev 383703 / 398502 Next

Change the colours of some of the labels of the x-axis

Hello,

You cannot pass a vector of colors to col.axis, you need to plot the 
axis twice, once the normal axis, like in your code, then overplot just 
those last 2 labels.


xlabels <- seq(trunc(as.POSIXct(first_day, format="%Y-%m-%d-%H-%M"), 
"days"), trunc(as.POSIXct(last_day, format="%Y-%m-%d-%H-%M"), "days"), 
by="12 hours")

plot(df_plot$data_POSIX, df_plot$hs1, type="b",
      xlim = c(min(xlabels), max(xlabels)), ylim=c(0, 10), col="blue", 
xaxt="n", axes=F, main="", xlab="", ylab="Snow height")
lines(df_plot$data_POSIX, df_plot$hs2, ylim=c(0, 10), col="red", type="b")
axis.POSIXct(1, at = xlabels, format="h%H-%d-%m-%y", pos=0, las = 2)
axis.POSIXct(1, at = tail(xlabels, 2),
              format="h%H-%d-%m-%y", pos=0, las = 2, col.axis = "red")

axis(side=2, at=seq(0, 15, 5))



Hope this helps,

Rui Barradas

?s 15:09 de 07/05/20, Stefano Sofia escreveu: