'How can I change the name of my x value in r plot

I have the plot:

 plot(Combined$TIMESTAMP,                              # Draw first time series
 Combined$GPP_NT_VUT_REF,
 type = "l",
 col = 2,
 ylim = c(0, 15),
 xlab = "",
 ylab = expression(paste("GPP [gC m"^"-2 "," day "^"-1]"))) +


 lines(Combined$TIMESTAMP,                             # Draw second time series
  Combined$GPP_WRF_mean,
  type = "l",
  col = 3) +

  legend("topright",                           # Add legend to plot
   c("OBS", "WRF"),
   lty = 1,
   col = 2:4)

which produces the timeseries graph with the name of x values equal to gen, feb, mar and I want to convert my x values in J,F,M,A,M,J...

I tried with:

 axis(1, at=1:12, labels=month.name, cex.axis=0.5) 

but it doesn't work - any help?



Solution 1:[1]

Keep the first letter of month.name or from month.abb:

month.1st.letter <- sub("(^[[:upper:]]).*$", "\\1", month.abb)

Then use this vector as the labels argument.

axis(1, at = 1:12, labels = month.1st.letter, cex.axis = 0.5) 

Edit

Start by removing the plus signs from the code, base R graphics do not add up. Then, in the plot instruction include xaxt = "n". And plot the axis right after it.

plot(Combined$TIMESTAMP,                              # Draw first time series
 Combined$GPP_NT_VUT_REF,
 type = "l",
 col = 2,
 ylim = c(0, 15),
 xaxt = "n",        # here, no x axis
 xlab = "",
 ylab = expression(paste("GPP [gC m"^"-2 "," day "^"-1]")))
axis(1, at = 1:12, labels = month.1st.letter, cex.axis = 0.5) 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1