How to make a iris data as ggplot graph? help me to make that

Hello in the middle of doing my assignment, i really don't have any idea and what can i do for this problem.
To make a ggplot2 graph through iris data, i made a gather
my thing is iris<-gather(iris, key = "Species", value = "value", c("setosa","versicolor","virginica"))
but answer was
Unknown column setosa
Run rlang::last_error() to see where the error occurred.
What's the problem???
Please help me to solve this problem.
Graph has to be like that


Let me know the solution
Thanks

Since this is for an assignment I can't give you a complete solution to produce the plot (check our homework policy), but I can help you with the gathering step, instead of specifying the values of the Species column (i.e. c("setosa","versicolor","virginica")), you have to tell gather() function, to exclude the Species column from the gathering, like this:

library(tidyverse)

iris %>%
    gather(key = feature, value = value, -Species)
#> # A tibble: 600 x 3
#>    Species feature      value
#>    <fct>   <chr>        <dbl>
#>  1 setosa  Sepal.Length   5.1
#>  2 setosa  Sepal.Length   4.9
#>  3 setosa  Sepal.Length   4.7
#>  4 setosa  Sepal.Length   4.6
#>  5 setosa  Sepal.Length   5  
#>  6 setosa  Sepal.Length   5.4
#>  7 setosa  Sepal.Length   4.6
#>  8 setosa  Sepal.Length   5  
#>  9 setosa  Sepal.Length   4.4
#> 10 setosa  Sepal.Length   4.9
#> # … with 590 more rows

Created on 2019-12-01 by the reprex package (v0.3.0.9000)

As an extra hint, you can use ggplot2::geom_jitter() to produce that kind of plot.

2 Likes

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