{"action":"opened","issue":{"url":"https://api.github.com/repos/joshuaulrich/xts/issues/138","repository_url":"https://api.github.com/repos/joshuaulrich/xts","labels_url":"https://api.github.com/repos/joshuaulrich/xts/issues/138/labels{/name}","comments_url":"https://api.github.com/repos/joshuaulrich/xts/issues/138/comments","events_url":"https://api.github.com/repos/joshuaulrich/xts/issues/138/events","html_url":"https://github.com/joshuaulrich/xts/issues/138","id":152050752,"number":138,"title":"Problem with index class in plot.xts()","user":{"login":"olliefr","id":967105,"avatar_url":"https://avatars.githubusercontent.com/u/967105?v=3","gravatar_id":"","url":"https://api.github.com/users/olliefr","html_url":"https://github.com/olliefr","followers_url":"https://api.github.com/users/olliefr/followers","following_url":"https://api.github.com/users/olliefr/following{/other_user}","gists_url":"https://api.github.com/users/olliefr/gists{/gist_id}","starred_url":"https://api.github.com/users/olliefr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olliefr/subscriptions","organizations_url":"https://api.github.com/users/olliefr/orgs","repos_url":"https://api.github.com/users/olliefr/repos","events_url":"https://api.github.com/users/olliefr/events{/privacy}","received_events_url":"https://api.github.com/users/olliefr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-30T20:23:19Z","updated_at":"2016-04-30T20:23:19Z","closed_at":null,"body":"I am experiencing a problem in setting custom X axis labels using `plot.xts()`. I did some debugging and I have more or less found why this happens, but I have no idea why `xts ` does what it does. Please advise, if you can.\r\n\r\nFirst, I load the data set:\r\n\r\n```\r\ndow <- read.csv('data/DJA.csv', header = TRUE, stringsAsFactors = FALSE)\r\nnames(dow) <- c('Date', 'Value')\r\ndow$Value <- as.numeric(dow$Value)\r\ndow$Date <- as.Date(dow$Date, format = \"%m/%d/%Y\")\r\n```\r\n\r\nThe `head(dow)` yields the following\r\n\r\n```\r\n             Value\r\n1914-07-30 52.3197\r\n1914-12-12 54.6200\r\n1914-12-14 56.7600\r\n1914-12-15 55.0700\r\n1914-12-16 55.3500\r\n1914-12-17 55.3600\r\n\r\n```\r\nAnd the data structure looks like this in the environment inspector:\r\n\r\n![xts-debugging-1](https://cloud.githubusercontent.com/assets/967105/14938350/86e37890-0f18-11e6-9568-9cd49f370602.JPG)\r\n\r\nNow, I would like to plot it, so I do\r\n\r\n`plot(dow, xaxt='n')`\r\n\r\n![xts-debugging-2](https://cloud.githubusercontent.com/assets/967105/14938351/86e5e224-0f18-11e6-9954-fa89b8c74037.JPG)\r\n\r\nSo plot figures out this is an xts object and plots it. Now I would like to set the values for X axis.\r\n\r\nI do something like this, the exact line is not that important\r\n\r\n`at = format(index(dow), '%m') == '01' & format(index(dow), '%d') == '10'`\r\n\r\nThis gives me a logical vector, which I can use to index into the values\r\n\r\n`axis(side=1, at=index(dow)[at], labels = format(index(dow)[at], '%Y'))`\r\n\r\nThis does not work. It produces either an empty axis or a single value in the middle of the axis which does not make sense.\r\n\r\nIt does, however, work if I call `plot.xts()`, providing explicit value for `x` and `y`:\r\n\r\n`plot(x=index(dow), y=dow$Value, xaxt='n')`\r\n\r\nAnd the code for the labels is the same as the above.\r\n\r\nSo, to solve this I had an intuition that in the former case when `plot.xts()` indexes the dow object, it uses something wrong as an index, and then cannot match the values that I pass into `axis()` with the ones that it believes to be the values of the index. This turns out to be the case.\r\n\r\nIn the latter case, when the index and the values are passed in separately at some point `index.xts()` gets called which has the following code executed (I stepped through it in the debugger):\r\n\r\n```\r\nvalue <- indexClass(x)\r\n if (value[[1]] == \"Date\") \r\n    return(structure(.index(x)%/%86400, class = \"Date\"))\r\n```\r\n\r\nThe value is indeed, a \"Date\", so the `.index(x)` values undergo this transformation before being used to produce the labels.\r\n\r\nIn the former case, when a single dow object is being passed, the `plot.xts()` calls `.index(x)` to extract the index and ignores that its type is a Date!\r\n\r\nIn `plot.xts()` the following line of code is run:\r\n`xycoords <- xy.coords(.index(x), x[, 1])`\r\n\r\nAnd `head(.index(x))` returns something like\r\n\r\n```\r\n-1749081600 -1737417600 -1737244800 -1737158400 -1737072000 -1736985600\r\n```\r\n\r\nAnd this somehow becomes the \"labels\" that it is using to match against those I provide with `axis()` call, and of course they never match.\r\n\r\nI am working under assumption that xts-time series objects usually are indexed by Date values, so if it can plot them correctly using `plot(dow)` syntax, then it should also allow to set custom labels without requiring something like `plot(x=index(dow), y=dow$Value)\r\n![xts-debugging-1](https://cloud.githubusercontent.com/assets/967105/14938347/6de6935e-0f18-11e6-9f52-69c0d8613822.JPG)`.\r\n\r\nIf I got the essence of the problem right, why does it do the index transformation in one case, but not the other?\r\n"}}