[R-SIG-Finance] [R-sig-finance] Missing tick mark labels from barChart / quantmod - plot.xts missing

Wind2 windspeedo at qq.com
Sun Dec 21 14:45:12 CET 2008


I checked the help again and fount that the format string of "%n" is not
supported for windows now.
So I just changed the axTicksByTime a little and run the following codes:
>source("axTicksByTimeModified.r")
>assignInNamespace("axTicksByTime",axTicksByTime, ns="xts") 
Everything is OK now.
Perfect since assignInNamespace has not changed the xts package itself.  I
don't like to mess up the xts package. :)


Wind2 wrote:
> 
> Dear Jeff,
> I am glad to tell you that I have traced the problem into a line of code 
> concerning the parameter of "%n" in time format string.
> Here is the data for test:
>>x<-xts(x[,-1],as.Date(x[,1]))     #convert data frame to xts.   
>>head(x)
>            Symbol     Close   
> 1990-12-19 SH000001     99.98
> 1990-12-20 SH000001    104.39 
> 1990-12-21 SH000001    109.13 
> 1990-12-24 SH000001    114.55 
> 1990-12-25 SH000001    120.25
>>plot(x[,"Close"],auto.grid=TRUE,minor.ticks=FALSE)
> The plot is OK except that no date labels for x axis.  Major ticks and
> grids are all Ok for x and y axis.
> 
> Then I used the xts:::plot.xts method  you taught me to get the definition
> of plot.xts.
> I found that a line of code as
> ep <- axTicksByTime(x, "auto")
> returned ep with no names
>>names(ep)
> [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
> 
> Then I trace the axTicksByTime.  There is a line of code as:
> names(ep) <- format(index(x)[ep], fmt)
> The  fmt is something like "%b %d%n%Y".
> 
>> ep
>                                                                            
>    1   10  263  514  767 1010 1259 1505 1748 1994 2233 2472 2712 2949 3190 
>                          
> 3433 3674 3915 4157 4393 
> 
>> format(index(x)[ep])
>  [1] "1990-12-19" "1991-01-02" "1992-01-02" "1993-01-04" "1994-01-03"
> "1995-01-03" "1996-01-02" "1997-01-02" "1998-01-05"
> [10] "1999-01-04" "2000-01-04" "2001-01-02" "2002-01-04" "2003-01-02"
> "2004-01-02" "2005-01-04" "2006-01-04" "2007-01-04"
> [19] "2008-01-02" "2008-12-18"
>> 
>> format(index(x)[ep], "%b %d%n%Y")
>  [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
>> 
> I test with several definitions of format string, the format() will output
> nothing with "%n" in the format string.   If I remove "%n", everything is
> OK.
> 
> The help said that "%n" is for a  new line.
> I guess maybe "%n" just conflict with something in my computer.
> 
> Since my vista is in Chinese, the "%b" will output month names in Chinese. 
> I omit the "%b".  The problem is still there.
>> format(index(x)[ep], "%d%n%Y")
>  [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
> 
> Then I changed the locale to US:
>> Sys.setlocale("LC_TIME","US")
> [1] "English_United States.1252"
> 
> format still has problems with "%n".
>> format(index(x)[ep], "%d%n%Y")
>  [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
>> format(index(x)[ep], "%b %Y")
>  [1] "Dec 1990" "Jan 1991" "Jan 1992" "Jan 1993" "Jan 1994" "Jan 1995"
> "Jan 1996" "Jan 1997" "Jan 1998" "Jan 1999"
> [11] "Jan 2000" "Jan 2001" "Jan 2002" "Jan 2003" "Jan 2004" "Jan 2005"
> "Jan 2006" "Jan 2007" "Jan 2008" "Dec 2008"
> 
> I could not trace the porblem futher into the definition of format()
> because of my limited knowledge of computer and R :(
> 
> I guess maybe you have told me the issue since you have said:
> "not showing line breaks in the date (windows doesn't recognize this)."
> Previously I did not understand your comment well because I am not
> familiar with R.  
> 
> If that's the case, I wonder whether there is some easy way for me to
> alter the code in axTicksByTime a little in my computer to make it worked.
> Thanks. 
> 
> Information on Package xts:
> URL:           http://r-forge.r-project.org/projects/xts/
> Packaged:      Tue Nov 18 09:15:14 2008; jryan
> Built:         R 2.7.2; i386-pc-mingw32; 2008-11-18 19:22:56; windows
> 
> Information on my computer:
> Fujitsu Notebook
> Windows Vista Basic, OEM, Chinese.
> R 2.7.2     (Previously I have got the same problem in R 2.8)
> 
> Regards,
> Wind
> 
> 
> Jeff Ryan wrote:
>> 
>> Hi Wind,
>> 
>> plot.xts is there, just not exported.  This means it gets called when
>> an xts object is passed to plot()
>> 
>> xts:::plot.xts
>> 
>> That aside, the issue is somewhere else.  I have tried the CRAN
>> release, the R-forge package, and the dev code on R-forge and all seem
>> to show an x axis with dates.
>> 
>> There may be a formatting issue with Windows and the release you have
>> not showing line breaks in the date (windows doesn't recognize this).
>> Try using this version (though probably won't fix either):
>> 
>> install.packages("xts",repos="http://R-Forge.R-project.org")
>> 
>> chartSeries and plot.xts use axTicksByTime to format the labels.  The
>> issue most likely is that of the line breaks.
>> 
>> All of the above have been fixed in not yet released /dev branch of
>> xts.  We are hoping to have that ready in the next few weeks.
>> 
>> Jeff
>> 
>> On Sun, Nov 16, 2008 at 3:24 AM, 风 <windspeedo at qq.com> wrote:
>>> Dear Jeff and R experts,
>>> I wonder whether you have received the previous email on this matter.
>>> I have narrow the problem to plot.xts missing.
>>>
>>>>require(quantmod)
>>> Loading required package: quantmod
>>> Loading required package: xts
>>> Loading required package: zoo
>>> Attaching package: 'zoo'
>>>        The following object(s) are masked from package:base :
>>>         as.Date.numeric
>>> Loading required package: Defaults
>>> quantmod: Quantitative Financial Modelling Framework
>>> Version 0.3-6, Revision 433
>>> http://www.quantmod.com
>>>
>>>>getSymbols('AAPL')
>>> [1] "AAPL"
>>>>barChart(AAPL)
>>> #successful.  But NO date label for x axis labels.
>>>>a<-Cl(AAPL)
>>>>class(a)
>>> [1] "xts" "zoo"
>>>>plot.zoo(a)
>>> #successful.  There are annual label for x axis major ticks.
>>>>chartSeries(a)
>>> Error in sum(poss.new) : invalid 'type' (list) of argument
>>>>plot(a)
>>> #no date label for x  axis ticks
>>>>plot(as.xts(a))
>>> #same graph as the above. still no date label for x axis ticks
>>>>plot.xts(a)
>>> Error: could not find function "plot.xts"
>>>> ?plot.xts
>>> #the help window for plot.xts poped up.
>>>
>>>>library(help=xts)
>>> #window poped up with the following content:
>>> Version:       0.0-15
>>> Revision:      139
>>> Date:          2007-06-04
>>> Author:        Jeffrey A. Ryan, Josh M. Ulrich
>>> Depends:       zoo
>>> ...
>>> License:       GPL-3
>>> URL:           http://r-forge.r-project.org/projects/xts/
>>> Packaged:      Mon Jun 9 23:47:46 2008; jryan
>>> Built:         R 2.7.2; i386-pc-mingw32; 2008-10-15 23:19:56; windows
>>> Index:
>>> ...
>>> plot.xts                Plotting xts Objects
>>> ...
>>>
>>> It seems that plot.zoo does its job but plot.xts may have some problem.
>>>
>>> Besides, the OS is Vista Oem on a notebook.  R is 2.7.2 or 2.8.0.
>>>
>>> I wonder whether it is enough for R experts to diagnose the problem.
>>> Thanks.
>>>
>>> Wind
>> 
>> 
>> 
>> -- 
>> Jeffrey Ryan
>> jeffrey.ryan at insightalgo.com
>> 
>> ia: insight algorithmics
>> www.insightalgo.com
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Missing-tick-mark-labels-from-barChart---quantmod---plot.xts-missing-tp20523627p21115185.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list