Trouble shooting " Error in eval(expr, env) : object not found" error

**I am new user in R. Am trying to do data visualization using the ggvis to plot scatter plot for my data. A m using the iris data from the url("http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data repository. when running the code iris%>%ggvis(Septal_length, Septal_width, fill= species)%>% layer_points() i am getting the Error: Error in eval(expr, env) : object 'species' not found. How can i fix this?

  • RStudio Edition: (Desktop )
  • RStudio Version: 5
  • OS Version: windows10
  • R Version: 5
  • sessionInfo():

Referred here from support.rstudio.com

try

names(iris)

to check the spelling (and case-ing!) of the variable names. I'm thinking you might need Species rather than species

Thank you for the answer. But i have checked my colnames and the are;

colnames(iris)
[1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
using the Print(iris) my table is displayed with this names
print(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
7 4.6 3.4 1.4 0.3 setosa

But once i run the code
iris%>%ggvis(Sepal.Length , Sepal.Width, fill= Species )%>% layer_points()
i get the Error
Error in eval(expr, env) : object 'Species' not found
i have tried to rename the colnames but still am getting the error

@Edida maybe you need to try "Species" I think R treats anything without quotation as object.

Thank you Xiaoni. Adding " " to the colnames has solved it . Thank you

1 Like

You can also do it this way:

#install.packages("ggvis")
library(ggvis)
data(iris)
head(iris)

help(ggvis)  # In the Help pane, scroll down to the Examples section re: syntax

iris %>% ggvis(~Sepal.Length , ~Sepal.Width, fill= ~Species)  # The points layer is guessed

iris %>% 
  ggvis(~Sepal.Length , ~Sepal.Width) %>% 
  layer_points(fill:="blue")  # The points layer is specified

HTH

i have drawn my scatter plot using
iris%>%ggvis("Sepal.Length" , "Sepal.Width", fill= "Species" )%>% layer_points() however, my graph is blank
image
i feel that my grids maybe are too big but i don't know how to adjust them.. Or probably there are no points in my plot. How can i solve this

The correct syntax for ggvis is like this:

iris %>% ggvis(~Sepal.Length , ~Sepal.Width, fill= ~Species) %>% layer_points() 

See: help(ggvis).

Not this

iris %>% ggvis("Sepal.Length" , "Sepal.Width", fill= "Species") %>% layer_points() 

I'm not sure why ggvis() renders a blank plot with the incorrect syntax - perhaps an error message would be better.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.