如何将x轴标签从一个字符更改为另一个字符? [英] How to change the x-axis labels from a character to a different one?

查看:85
本文介绍了如何将x轴标签从一个字符更改为另一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对xaxis标签有疑问.与此处讨论的内容相反:

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

解决方案

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"))

这篇关于如何将x轴标签从一个字符更改为另一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆