简体   繁体   中英

Plotting multiple series curves in r

I have a csv with 3 columns. I wish to plot AMV on the x axis and duration_in_traffic on the y axis.

In this case I have two series and I would like to draw a polynomial regression fit line for this specific series. For the following data set I would therefore end up with two curves.

count_id    AMV duration_in_traffic
16012E  4004    99
16012E  4026    94
16012E  4099    93
16012E  4167    100
16012E  4239    97
16012E  4324    88
16012E  4941    104
16012E  5088    100
16012E  5283    100
16012E  5620    192
16012E  5946    276
16012E  6146    368
16012W  3622    97
16012W  3904    93
16012W  3979    94
16012W  4076    103
16012W  4189    96
16012W  4870    96
16012W  4899    252
16012W  5107    95
16012W  5659    102
16012W  6325    96
16012W  6460    341
16012W  6500    101

How do I plot per series in R?

df <- read.table(header = T, stringsAsFactors = F, text = "  count_id    AMV duration_in_traffic
                   16012E  4004    99
                   16012E  4026    94
                   16012E  4099    93
                   16012E  4167    100
                   16012E  4239    97
                   16012E  4324    88
                   16012E  4941    104
                   16012E  5088    100
                   16012E  5283    100
                   16012E  5620    192
                   16012E  5946    276
                   16012E  6146    368
                   16012W  3622    97
                   16012W  3904    93
                   16012W  3979    94
                   16012W  4076    103
                   16012W  4189    96
                   16012W  4870    96
                   16012W  4899    252
                   16012W  5107    95
                   16012W  5659    102
                   16012W  6325    96
                   16012W  6460    341
                   16012W  6500    101")


library(ggplot2)

ggplot(aes(x = AMV, y = duration_in_traffic), data = df) + geom_point(aes(color = count_id)) + geom_smooth(aes(color = count_id), method= "lm", se = F, formula=y ~ poly(x, 3, raw=TRUE))

在此处输入图片说明

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