Search code examples
rplotaxisaxis-labels

How to change the x-axis labels from a character to a different one?


I've got a questions regarding the xaxis labels. In contrast to whats discussed in here:

How to specify the actual x axis values to plot as x axis ticks in R

I plotted a dataframe containing 10 columns. Each one is represented in a boxplot. For the x-axis my labels are Pipe1 till Pipe 10. Now I wanna change those labels to a specific ID for instance this way

windows()
par(mfrow= c(2,1),las=3)
boxplot(output.valid.fast,outline=F, xlab ="Pipes",ylab="RMSE(-)")
axis(1,at=c("Pipe1","Pipe2","Pipe3","Pipe4","Pipe5","Pipe6","Pipe7","Pipe8","Pipe9","Pipe10"),labels=c("1234","2345","3456","4567","5678","6789","78910","891011","9101112","10111213"))

everytime I'm doing so, I receive an error revealing the following:

In axis(1, at = c("Pipe1", "Pipe2", "Pipe3", "Pipe4", "Pipe5", "Pipe6",  :
  NAs introduced by coercion

What did I do wrong in here? I'd highly appreciate hints or advices. Cheers, Olli


Solution

  • Replace at = c("Pipe1", ... , "Pipe10") by at = 1:10.

    Example with 2 columns

    boxplot(data.frame(Pipe1 = 1:10, Pipe2 = 2:11), xaxt = "n")
    axis(1, at = 1:2, labels = c("1234","2345"))
    

    enter image description here