xts

Plotting an xts object using ggplot2

空扰寡人 提交于 2020-01-23 08:33:49
问题 I'm wanting to plot an xts object using ggplot2 but getting an error. Here is what I'm doing: dates <- c("2014-10-01", "2014-11-01", "2014-12-01", "2015-01-01", "2015-02-01") value <- as.numeric(c(3, 4, 5, 6, 5)) new_df <- data_frame(dates, value) new_df$dates <- as.Date(dates) new_df <- as.xts(new_df[,-1], order.by = new_df$dates) Now I try to plot it using ggplot2: ggplot(new_df, aes(x = index, y = value)) + geom_point() I get the following error: Error in (function (..., row.names = NULL,

Display time index in R xts

て烟熏妆下的殇ゞ 提交于 2020-01-17 03:47:09
问题 I want to parse csv with micro-second timed index. So, I wrote code like this: t<-read.zoo("test", index.column = 1, sep=",",header=TRUE, format="%Y-%m-%d %H:%M:%OS") t.xts<-as.xts(t) after then, I tried to display this but I couldn't see time information on the index. > t.xts[1:10,4] drate 2010-09-28 " -149" 2010-09-28 " -269" 2010-09-28 " -358" 2010-09-28 " -358" 2010-09-28 " -239" 2010-09-28 " -149" 2010-09-28 " -149" 2010-09-28 " -149" 2010-09-28 " -119" 2010-09-28 " -149" I tried options

Add Horizontal Line to xts Plot

点点圈 提交于 2020-01-16 18:39:13
问题 I would like to add a horizontal line to an xts object plot. I know there is the addEventLines() function in xts to add vertical lines, but the following does not add a line to an xts plot: abline(h=abc, col="green") Is there a workaround for this other than adding a new column to the object itself before plotting? 回答1: You can just create some constant data and use the lines function. Below is a solution together with a reproducible example. # load package require(xts) # get data data(sample

Using the Rblapi package to pull data

▼魔方 西西 提交于 2020-01-16 04:35:08
问题 I have a list of ISINs which is my only source of information. In Excel I can catch the Bloomber ticker which is needed in many cases because it specifies the code of the exchange on which the asset is traded. To do so I only have to add "... Equity isin" in a BDP()-Formula where "..." is a placeholder for the ISIN. So with the new Rblpapi package (which is by the way a fantastic tool!) I can try to do the same: Here is a list of random ISINs isins = c("LU0942970442", "LU0997545750" ,

how to format a column with duplicate dates in r

安稳与你 提交于 2020-01-16 00:38:07
问题 I have a fairly large dataset saved in a .txt file, that i read into my environment using fread() from data.table . I would like to organize the data so that it looks like this: # Desired output: Column headers = [ Date, Company Names, RET, RETX,PRC, vwretd, ewrtd, sprtrn] # rows contain stock return data... (I made up the values below to save time, but the format must remain). Date AMERICAN CAR & FDRY CO ALASKA JUNEAU GOLD MNG C RET RETX vwretd ... 1925-12-31 0.0432 0.0231 0.0032 0.053 ...

overlap(intersect) time interval and xts

自闭症网瘾萝莉.ら 提交于 2020-01-15 09:36:07
问题 There's two time datasets: data from raincollector -- time interval ti with start , end and rain p (total amount of rain per period in mm) ti <- data.frame( start = c("2017-06-05 19:30:00", "2017-06-06 12:00:00"), end = c("2017-06-05 23:30:00", "2017-06-06 14:00:00"), p = c(16.4, 4.4) ) ti[,1] <- as.POSIXct(ti[, 1]) ti[,2] <- as.POSIXct(ti[, 2]) and timeseries ts from gauging station with time and parameter q , which is the water discharge (cu. m per sec) ts <- data.frame(stringsAsFactors

How do I set width of candles in candle chart using plot.xts?

非 Y 不嫁゛ 提交于 2020-01-14 08:44:21
问题 I have simple OHLC data in and XTS SF <- structure(c(1.064, 1.07, 1.071, 1.08, 1.08, 1.076, 1.078, 1.08, 1.08, 1.082, 1.081, 1.082, 1.074, 1.07, 1.073, 1.075, 1.081, 1.084, 1.092, 1.091, 1.097, 1.095, 1.099, 1.094, 1.096, 1.097, 1.096, 1.096, 1.097, 1.091, 1.078, 1.083, 1.088, 1.084, 1.081, 1.095, 1.096, 1.085, 1.074, 1.075, 1.073, 1.07, 1.068, 1.072, 1.084, 1.08, 1.081, 1.077, 1.081, 1.083, 1.084, 1.083, 1.082, 1.082, 1.075, 1.074, 1.075, 1.092, 1.086, 1.092, 1.093, 1.098, 1.102, 1.103, 1

Creating xts time series

瘦欲@ 提交于 2020-01-14 06:54:06
问题 zz <- textConnection("strtimestamp, jstimestamp, 61757, 61754, 61760, 61753, 61758, 61762, 61756, 61759, 61761, 61755, 61752 '01/01/2007 00:00:00', 1167606000000, 1145.3, 1647.3, 612, 963.3, 1063.5, 2294.3, 726.9, 280.8, 5182.4, 739.5, 1631.7 '01/01/2007 00:05:00', 1167606300000, 1116.7, 1625.4, 695.3, 948.4, 1111.8, 2262, 736.5, 202.7, 5135.8, 733, 1608.1 '01/01/2007 00:10:00', 1167606600000, 1100.3, 1613.4, 614.9, 957.5, 1059.8, 2261.6, 723.2, 238.5, 5114.5, 733, 1599.1 '01/01/2007 00:13:41

R Month by Month Percent Growth on an XTS objects

牧云@^-^@ 提交于 2020-01-13 03:56:05
问题 How might I plot month to month growth for the following data: A 2008-07-01 0 2008-08-01 87 2008-09-01 257 2008-10-01 294 2008-11-01 325 2008-12-01 299 (In dput format, before Joshua hunts me down and murders me in my sleep): structure(c(0L, 87L, 257L, 294L, 325L, 299L), .indexCLASS = c("POSIXt", "POSIXct"), .indexTZ = "", index = structure(c(1214884800, 1217563200, 1220241600, 1222833600, 1225512000, 1228107600), tzone = "", tclass = c("POSIXt", "POSIXct")), .Dim = c(6L, 1L), .Dimnames =

time zones in POSIXct and xts, converting from GMT in R

主宰稳场 提交于 2020-01-12 21:25:12
问题 I have a bunch of 1 minute returns in an xts object with the index being POSIXct and time zone being GMT. The returns are on NYSE so I would like to convert to the eastern time zone but I would like to take care of the daylight savings time properly. What is the best way of doing this? I am a bit confused between the EST timezone and the EDT timezone. I would like my times to convert properly to the NY time in winter and summer. 回答1: Use indexTZ<- and the America/New_York timezone > tail(SPY)