1

I'm studying matplot and ggplot2.

I am facing an issue while trying to convert matplot to ggplot2

matplot(iris[,1:4],type="l")

legend("topleft",names(iris)[1:4],lty=c(1,2,3,4),col=c(1,2,3,4))

I really can't bring the Species part to ggplot2.

How can I convert this?

1
  • 2
    There is no "Species part" in your matplot. Commented Dec 9, 2019 at 8:49

1 Answer 1

1

Probably, something like this

library(tidyverse)

iris %>%
  select(1:4) %>%
  mutate(row = row_number()) %>%
  pivot_longer(cols = -row) %>%
  ggplot() + aes(row, value, color = name) + geom_line()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.