Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot2用于日内财务数据_R_Ggplot2 - Fatal编程技术网

R ggplot2用于日内财务数据

R ggplot2用于日内财务数据,r,ggplot2,R,Ggplot2,我有日内交易数据,我正试图用ggplot绘制 对于给定的一天,数据看起来是这样的,例如 head(q1) time last bid ask volume center 1 2014-03-19 09:30:00.480 63.74 63.39 63.74 200 11 2 2014-03-19 09:30:00.645 63.41 63.41 63.60 100 11 3 2014-03-19 09:30:00.645 63.48 63.41 63.60

我有日内交易数据,我正试图用ggplot绘制

对于给定的一天,数据看起来是这样的,例如

head(q1)
time  last   bid   ask volume center
1 2014-03-19 09:30:00.480 63.74 63.39 63.74    200     11
2 2014-03-19 09:30:00.645 63.41 63.41 63.60    100     11
3 2014-03-19 09:30:00.645 63.48 63.41 63.60    100     11
4 2014-03-19 09:30:02.792 63.59 63.44 63.60    100     11
5 2014-03-19 09:30:03.023 63.74 63.44 63.75    100     12
6 2014-03-19 09:30:12.987 63.72 63.44 63.76    100     11

tail(q1)
time  last   bid   ask volume center
2116 2014-03-19 15:59:56.266 61.68 61.67 61.74    168     12
2117 2014-03-19 15:59:58.515 61.68 61.68 61.73    100     28
2118 2014-03-19 15:59:59.109 61.69 61.68 61.73    500     11
2119 2014-03-19 16:00:00.411 61.72 61.69 61.73    100     11
2120 2014-03-19 16:00:00.411 61.72 61.69 61.73    200     11
2121 2014-03-19 16:00:00.411 61.72 61.69 61.73    351     11

使用gglot可以很容易地可视化一天的数据,而我遇到的问题是在同一个绘图上将多天连接在一起。如果我在数据帧q1和q2中有连续两天,那么当市场关闭时,我如何在没有时间间隔的情况下在单个图上绘制这些数据帧,以及将一天的结束与另一天的结束连接起来的线?

您可以尝试创建一种新的转换,将白天转换为无缝的交易时间:

 9:30          -> 0
12:00          -> approx. 0.5
16:00          -> 1
 9:30 next day -> 1
以下几点可以做到,但我自己还没有尝试过:

library(scales)
trading_day_trans <- function() {
    trans_new("trading_day", trans, inv,
              pretty_breaks(), domain = domain)
}

ggplot(rbind.fill(q1, q2)) + ... + coord_trans(xtrans = "trading_day")
您需要提供trans变换函数,time->linear,inv逆变换,linear->time和domain长度为2的时间向量,min-max


>根据

你有没有尝试过一个白天的情节?嗨,我确实考虑过了,但是我真的希望数据有相同的Y-AxIS。听起来像是一个可能的解决方案,但是,我真的希望能够保持时间标记。如果可能的话。克雷格:我的草图上的时间标记会发生什么?你能更新你的问题或者问一个新的问题吗?读了你的链接,我觉得很明显原来的标记没有被保留。我不确定我能不能用不同的措辞来表达这个问题。@Craig:不,这对我来说并不明显。你说的标记是什么意思?你有没有试着实施我的建议?