我有一个数字向量,并希望在y轴上按x轴上的名称绘制每个值.
例:
quantity <- c(3,5,2)
names(quantity) <- c("apples","bananas", "pears")
plot(quantity)
Run Code Online (Sandbox Code Playgroud)
每个值都沿着x轴绘制,其中包含索引号.1,2,3.我怎样才能展示它("苹果","香蕉","梨")?
Did*_*rts 10
您可以使用函数axis()添加标签.xaxt="n"内部的参数plot()将使得没有x轴标签(数字)的图.
plot(quantity,xaxt="n")
axis(1,at=1:3,labels=names(quantity))
Run Code Online (Sandbox Code Playgroud)