简体   繁体   English

带有 R 的基本时间序列直方图

[英]Basic Time-Series Histogram with R

I have a dataframe that looks like so:我有一个看起来像这样的数据框:

> x
                Timestamp Calls
1   [2014-11-13 20:40:02]    18
2   [2014-11-13 20:40:05]    16
3   [2014-11-13 20:40:11]    15

and so on.等等。

I would like to plot a histogram with 'Timestamp' values as the range and 'Calls' as the domain.我想绘制一个以“时间戳”值作为范围和“呼叫”作为域的直方图。 What is the most straightforward way to do so?最直接的方法是什么?

Keep in mind, I have very little experience with R, so this is very much an R 101 question.请记住,我对 R 的经验很少,所以这在很大程度上是一个 R 101 问题。 Thanks!谢谢!

df<-data.frame(time=c(1,2,3),Calls=c(18,16,15))
plot(df$time,df$Calls,type='l') 

Take a look at ?plot for more details about R 's basic plotting methods.查看?plot以了解有关R基本绘图方法的更多详细信息。

I found a slightly better approach that suited my needs in this particular case.在这种特殊情况下,我找到了一种更适合我的需求的更好的方法。

First, convert the timestamp to a plain integer to place on the x-axis:首先,将时间戳转换为普通整数以放置在 x 轴上:

Timeframe=as.numeric(strptime(Timeframe, "%Y-%m-%d %H:%M:%S"))

Now, for the visualization I'm looking for, I can use ggplot :现在,对于我正在寻找的可视化,我可以使用ggplot

raw_data <-read.csv("serverName.data.20150116.csv")
data <- transform(raw_data, Seconds=as.numeric(strptime(Timeframe, "%Y-%m-%d %H:%M:%S")))

p<-ggplot(count_data, aes(Seconds, Calls))+geom_point(color="blue")
p

And then I get a decent visualization of the data:然后我得到了一个不错的数据可视化:在此处输入图片说明 Playing with the graphical options in ggplot could give me more informative visualization, but as far as a straightforward plot to aid diagnostics, this will do.使用ggplot的图形选项可以为我提供更多信息丰富的可视化,但就帮助诊断的简单绘图而言,这是ggplot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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