Geom_smooth没有出现在简单图中 [英] Geom_smooth not appearing in simple plot
本文介绍了Geom_smooth没有出现在简单图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ggplot(R3L12, aes(x=Time, y=HeartRate)) +
geom_point() +
geom_smooth()
这是dput(head(R3L12,20))的输出
This is the output of dput(head(R3L12, 20))
structure(list(Date = c("2015-05-23", "2015-05-23", "2015-05-23",
"2015-05-23", "2015-05-23", "2015-05-23", "2015-05-23", "2015-05-23",
"2015-05-23", "2015-05-23", "2015-05-23", "2015-05-23", "2015-05-23",
"2015-05-23", "2015-05-23", "2015-05-23", "2015-05-23", "2015-05-23",
"2015-05-23", "2015-05-23"), Time = c("07:25:00", "07:40:00",
"07:45:00", "09:10:00", "11:45:00", "11:55:00", "12:05:00", "12:35:00",
"12:45:00", "13:30:00", "13:40:00", "13:45:00", "13:55:00", "14:00:00",
"14:05:00", "14:10:00", "14:20:00", "14:25:00", "14:30:00", "14:35:00"
), Turtle = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("R3L1", "R3L11",
"R3L12", "R3L2", "R3L4", "R3L8", "R3L9", "R4L8", "R8L1", "R8L4",
"R8NAT123"), class = "factor"), HeartRate = c(7.56457, 6.66759,
17.51107, 9.72277, 19.44553, 13.07674, 28.115, 14.99467, 17.16947,
40.40479, 37.76642, 29.98933, 43.5329, 49.61471, 47.74245, 44.10196,
21.35316, 44.68609, 49.25255, 29.98933)), row.names = c(NA, 20L
), class = "data.frame")
这是我尝试创建的绘图的代码.我很困惑,因为当我绘制它时,geom_smooth不会显示. Time
是一个因子变量,而 HeartRate
是一个double.我是R的新手,所以如果您需要更多信息,请告诉我!
Here is the code of a plot I tried to create. I'm confused because when I plot it, the geom_smooth doesn't show up. Time
is a factor variable, and HeartRate
is a double. I'm new to R so let me know if you need more information!
推荐答案
使用 lubridate
包的替代解决方案:
An alternative solution using lubridate
package:
library(lubridate)
library(scales)
library(dplyr)
library(ggplot2)
df %>%
mutate(DateTime = ymd_hms(paste(Date, Time))) %>%
ggplot(aes(x= DateTime, y = HeartRate))+
geom_point()+
geom_smooth()+
scale_x_datetime( breaks=date_breaks("1 hour"), labels = date_format("%H:%M"))
这篇关于Geom_smooth没有出现在简单图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文