简体   繁体   中英

How to convert matplot to ggplot2?

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?

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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