0
votes

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

I want the Y-axis to be the names of species, but instead it is showing factor values. 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?

1
First you ask for y-axis == Sepal.Length, then you code y=Species??? Might be better to use boxplot with horizontal=TRUEIRTFM
Sorry, I typed wrong while asking the question. the code is right that's how i wanted the axis.devanshu singhal

1 Answers

1
votes

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.

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

plot