x 轴上带有标签的绘图

use*_*211 4 r

我想要绘制 10 个不同分子的强度值的直线图,其中 x 轴为分子名称,y 轴为强度值。

我试过:

x = c("Mol 1","Mol 2","Mol 3","Mol 4","Mol 5","Mol 6","Mol 7","Mol 8","Mol 9","Mol 10")
intensity = c(428,409,388,378,373,140,137,138,139,144)
plot(x,intensity)
Run Code Online (Sandbox Code Playgroud)

但是却返回了这个错误信息?

plot.window(...) 中的错误:需要有限的“xlim”值另外:警告消息:1:在 xy.coords(x,y,xlabel,ylabel,log) 中:强制引入的 NA 2:在 min( x) : min 没有非缺失参数;返回 Inf 3:在 max(x) 中:max 没有非缺失参数;返回-Inf

jor*_*ran 5

因为您的 x 变量是离散的,所以您需要稍微不同地执行此操作:

plot(seq_along(x),intensity,type = "l",axes = FALSE)
axis(side = 2)
axis(side = 1,at = seq_along(x),labels = x)
Run Code Online (Sandbox Code Playgroud)

这个想法是,您使用 x 轴的数值创建绘图,然后只需添加特定的标签。

box()如果您错过了绘图周围的完整框,您可以添加一个电话。