根据时间在R中绘制数据 [英] Plotting data against time in R

查看:119
本文介绍了根据时间在R中绘制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,其中一列为日期/时间(内部存储为数字),其他列为数字/整数,我想根据日期/时间绘制数据。



使用以下内容填充数据框中的日期/时间。

  as.POSIXct(strptime(time,'%H:%M:%S%p%m /%d /% Y',tz ='GMT'))

class(table $ time ) numeric


  1. 如何以某种格式绘制和显示x轴上的数据为可读日期时间。

  2. 如何绘制行的子集,而不是所有行Ex: dateTime1 dateTime2 其中 dateTime1 dateTime2 是以特定格式给出的日期。


解决方案

您还可以使用 ggplot2 ,更具体地说, geom_point geom_line (请注意,我使用@plannapus的示例数据):

  require(ggplot2)
theme_set(theme_bw())#将主题改为我的偏好
ggplot(aes = time,y = variable),data = data)+ geom_point()



或使用线几何:

  ggplot(aes(x = time,y = variable),data = data)+ geom_line()



ggplot2 自动识别x轴的数据类型是一个日期,并相应地绘制轴。 / p>

I have a data frame with one column as date/time(stored internally as numeric) and other columns as numeric/integer and I want to plot data against date/time.

Date/time in the data frame was populated using the following.

as.POSIXct(strptime(time, '%H:%M:%S %p %m/%d/%Y',tz='GMT')) 

class(table$time) is numeric.

  1. How do I plot and show the data in x axis as readable date time in some format.
  2. How do I plot subset of rows and not all rows Ex: rows between dateTime1 and dateTime2 where dateTime1 and dateTime2 are date given in a certain format.

解决方案

You could also use ggplot2, more specifically geom_point or geom_line (note that I use the example data from @plannapus):

require(ggplot2)
theme_set(theme_bw()) # Change the theme to my preference
ggplot(aes(x = time, y = variable), data = data) + geom_point()

or using a line geometry:

ggplot(aes(x = time, y = variable), data = data) + geom_line()

ggplot2 automatically recognizes that the datatype of the x-axis is a date, and draws the axis accordingly.

这篇关于根据时间在R中绘制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆