0

I need to change the x-axis labels so they are words instead of numerals. Currently, the x-axis goes 1, 2, 3, etc. I would like it to go "Placement", "Fresh", etc.

    trendplot <- function(timeseries, color, index, first = FALSE, w = 4, add_main = ""){
  if (first) {
    plot.ts(timeseries[, index], col = color, lwd = w,
         ylim = c(-2, 2),
         ylab = "Scaled Relative Abundance",
         xlab = "Stage",
         main = paste0("Trend Plots", add_main)) # gsub(".", " ", colnames(timeseries)[index], fixed = TRUE)
  } else {
    lines(timeseries[, index], col = color, lwd = w)
  }
}

Update: This code works for what I wanted it be.

stages<-c('Placement','Fresh','Bloat One','Bloat Two','Post-Bloat One','Post-Bloat Two')
trendplot <- function(timeseries, color, index, first = FALSE, w = 4, add_main = ""){
  if (first) {
    plot.ts(timeseries[, index], col = color, lwd = w, axes = FALSE,
         ylim = c(-2, 2),
         ylab = "Scaled Measurement",
         xlab = "Time Point",
         main = paste0("Trend Plots", add_main)) # gsub(".", " ", colnames(timeseries)[index], fixed = TRUE)+
  } else {
    lines(timeseries[, index], col = color, lwd = w)
  }
  {axis(1, at=1:6, labels=stages, cex.axis=0.5)}
}
vmc333
  • 1
  • 1
  • `?plot.ts` is similar to base `plot`, you can add `axes = FALSE` and use `axis(1, 1:3, ...)` as in other base plots – rawr Apr 24 '22 at 03:48
  • do I need to make a list to rename the axis like c("Placement", "Fresh".... – vmc333 Apr 24 '22 at 14:41
  • yes, `axis(1, 1:2, c('Placement', 'Fresh', ...))` adds an axis to the bottom at 1, 2, ... with labels Placement, Fresh, ... – rawr Apr 24 '22 at 16:50

0 Answers0