简体   繁体   English

plot():Y轴上的文本标签

[英]plot(): text labels at Y axis

I am trying to plot a graph: 我正在尝试绘制图形:

X-axis: species (setosa,versicolor,virginica)
Y-axis: Sepal.Length

on the dataset containing three columns from iris data set: Sepal.Length, Sepal.Width, Species 在包含来自虹膜数据集的三列的数据集上:Sepal.Length,Sepal.Width,Species

I want the Y-axis to be the names of species, but instead it is showing factor values. 我希望Y轴成为物种的名称,但它显示的是因子值。 I tried the command: 我尝试了命令:

plot(x = file$Sepal.Length, y = levels(file$Species), col = file$Species)

is there any method to view the unique text values as Y-axis using plot() function? 有什么方法可以使用plot()函数将唯一的文本值查看为Y轴?

You can pass yaxt='n' to the initial plot() call to prevent automatic drawing of the y-axis, and then call axis() to manually draw your desired y-axis. 您可以将yaxt='n'传递给初始的plot()调用以防止自动绘制y轴,然后调用axis()手动绘制所需的y轴。

data(iris);
plot(iris$Sepal.Length,iris$Species,xlab='lol',ylab='lola',col=iris$Species,yaxt='n');
axis(2L,seq_len(nlevels(iris$Species)),levels(iris$Species));

情节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM