每个时间序列的多个图表

编程入门 行业动态 更新时间:2024-10-20 00:49:34
本文介绍了每个时间序列的多个图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下数据框,其中每个用户有 288 个观察值:

I have the following dataframe where each user has 288 observations:

User5 User8 User10 2015-01-01 00:00:00 12.3 10.3 17.5 2015-01-01 00:30:00 20.1 12.7 20.9 2015-01-01 01:00:00 12.8 9.2 17.8 2015-01-01 01:30:00 11.5 6.9 12.5 2015-01-01 02:00:00 12.2 9.2 7.5 2015-01-01 02:30:00 9.2 14.2 9.0 .................... .... .... .... 2015-01-01 23:30:00 11.2 10.7 16.8

如何制作包含每个时间序列的多个图表的图表?

How can I make a graph with multiple graphs of each time series?

推荐答案

另一种选择是将宽格式转换为长格式,然后在同一个图中绘制所有内容.下面是使用@G 发布的 DF 的代码.格洛腾迪克

Another option is to convert from wide to long format then plot everything in the same graph. Below is the code that use the DF posted by @G. Grothendieck

library(tidyverse) library(scales) # Convert Time from factor to Date/Time DF$Time <- as.POSIXct(DF$Time) # Convert from wide to long format (`tidyr::gather`) df_long <- DF %>% gather(key = "user", value = "value", -Time) # Plot all together, color based on User # We use pretty_breaks() from scales package for automatic Date/Time labeling ggplot(df_long, aes(Time, value, group = user, color = user)) + geom_line() + scale_x_datetime(breaks = pretty_breaks()) + theme_bw()

要在单独的面板中绘制每个用户,请使用 facet_grid

to plot each user in a separated panel, use facet_grid

ggplot(df_long, aes(Time, value, group = user, color = user)) + geom_line() + scale_x_datetime(breaks = pretty_breaks()) + theme_bw() + facet_grid(user ~ .)

更多推荐

每个时间序列的多个图表

本文发布于:2023-07-18 04:42:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141117.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   图表   序列   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!