用基R表示数据子集

用基R表示数据子集,r,plot,graph,R,Plot,Graph,我的室内训练器(自行车)有问题,我想尝试探索数据,看看是否能找出问题。一般来说,我对R不是很在行,但我参加了一门使用R的数据可视化课程,我想我对一些优秀的图形来说已经走了一半。我希望这个社区的一些建议能帮助我完成这件事。我知道很多人都是ggplot的说教者,我尊重这一点,但我认为这一阶段我试图在我所知道的范围内扩大,而不是试图从头开始学习一整套新的功能。我把数据放在了底部 mymindata<-load(file = "Indoor Cycling Data - Old.Rdat

我的室内训练器(自行车)有问题,我想尝试探索数据,看看是否能找出问题。一般来说,我对R不是很在行,但我参加了一门使用R的数据可视化课程,我想我对一些优秀的图形来说已经走了一半。我希望这个社区的一些建议能帮助我完成这件事。我知道很多人都是ggplot的说教者,我尊重这一点,但我认为这一阶段我试图在我所知道的范围内扩大,而不是试图从头开始学习一整套新的功能。我把数据放在了底部

mymindata<-load(file = "Indoor Cycling Data - Old.Rdata")
我的数据使用dput
mymindata然后绘制子集,尝试:

# set up plot
plot(NULL, type = "l", 
     axes=F,
     xlim=c(0,100), 
     ylim=c(0, 60),   
     ylab="Speek (kph)", 
     xlab="Workout Time (as %)",
     main = "Cycling Speed over Time", font.main = 2)
axis(2, col="black", tck = 0.01, cex.axis = .8, las = 1)
axis(1, col="black", tck = 0.01, cex.axis = .8)

# all data, do not plot
# lines(mymindata$time_pcnt, mymindata$speed, col="blue", lwd=1)

# 21 Jan
with(subset(mymindata[mymindata$date == "2021-01-21", ]),
     lines(time_pcnt, speed, col = "red"))
# 24 Jan
with(subset(mymindata[mymindata$date == "2021-01-24", ]),
     lines(time_pcnt, speed, col = "green"))

mymindata <- structure(list(date = c("2021-01-21", "2021-01-21", "2021-01-21", 
"2021-01-21", "2021-01-21", "2021-01-21", "2021-01-21", "2021-01-21", 
"2021-01-21", "2021-01-21", "2021-01-21", "2021-01-24", "2021-01-24", 
"2021-01-24", "2021-01-24", "2021-01-24", "2021-01-24", "2021-01-24", 
"2021-01-24", "2021-01-24", "2021-01-24", "2021-01-24"), speed = c(22, 
26.7, 25.33, 27.85, 34.33, 40.31, 41.52, 46.66, 54.78, 58.75, 
47, 19, 27.91, 28.08, 28.22, 26.5, 28.28, 28.52, 30, 28.99, 29.89, 
20.73), time_pcnt = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 
100, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100), type = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L), .Label = c("Unformatted Workout", "Preset Workout"
), class = "factor")), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20", "21", "22"))
# set up plot
plot(NULL, type = "l", 
     axes=F,
     xlim=c(0,100), 
     ylim=c(0, 60),   
     ylab="Speek (kph)", 
     xlab="Workout Time (as %)",
     main = "Cycling Speed over Time", font.main = 2)
axis(2, col="black", tck = 0.01, cex.axis = .8, las = 1)
axis(1, col="black", tck = 0.01, cex.axis = .8)

# all data, do not plot
# lines(mymindata$time_pcnt, mymindata$speed, col="blue", lwd=1)

# 21 Jan
with(subset(mymindata[mymindata$date == "2021-01-21", ]),
     lines(time_pcnt, speed, col = "red"))
# 24 Jan
with(subset(mymindata[mymindata$date == "2021-01-24", ]),
     lines(time_pcnt, speed, col = "green"))