6

I have just started playing with the quantmod package. The documentation is however, quite sparse (perhaps understandably, since it is OSS).

I am currently using barChart() which is a nice wrapper around chartSeries() and does most of what I want, but the default chart it produces are not quite what I want. To be specific, I want to tweak the charts produced by barChart() to suit my needs - however, since I am a newbie, I don't know whether my "tweaks" can be provided as options to the wrapper barChart(), or if I need to call chartSeries() directly, with specific arguments.

I have been tearing my hair out trying to do the following:

  1. replace the horrible {start date}/{end date} text in the top right hand of the chart produced by barChart() with text of my own choosing

  2. specify the formating to be used on the X axis (for example, show only the last two digits of the century. i.e. '98, '99, '00, '01 etc)

  3. 'Force' both top chart and the bottom chart to have their Y values printed on the left hand side of the chart

  4. Add an aditional series to the bottom chart

  5. Use different up/down colors for the bottom chart (defaults the using the same up/down colors for both top and bottom charts)

  6. Plot just the top chart (no bottom chart)

  7. Specify X axis, Y axis grid line spacings for top chart, for bottom chart

  8. Write the image to an alternative output (e.g. png image or pdf document) instead of the graphics device

Can anyone help with any (or all) of the above?.

Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
  • I have to say that I get seriously annoyed when anonymous people, who usually have contributed little to the community, criticize FOSS. That said, quantmod is one of the better documented packages (in the package and on the site), which isn't to say it couldn't be improved. – Joshua Ulrich Feb 05 '12 at 15:54
  • @JoshuaUlrich: I understand (and share) your sentiment. My question was not meant as a critisicm (although I can see how it can be construed as one). I am a BIG fan of OSS, and although I haven't contributed anything to R (yet), I have contributed both code and money to many OSS projects that I regularly use (PostgreSQL and zeroMQ are two that come to mind). – Homunculus Reticulli Feb 05 '12 at 17:39
  • You might find http://stackoverflow.com/questions/8815697/r-quantmod-multiple-charts-all-using-the-same-y-axis also useful. (Especially regarding your number 5, as by using two calls to chartSeries you can definitely control the colours.) – Darren Cook Feb 06 '12 at 13:22
  • 1
    @Homunculus Reticulli, if you replace "horrible" by "useful", in the above, you'll find your question may no longer be construed as a criticism... – PatrickT Mar 28 '13 at 23:00

2 Answers2

5
  1. This functionality isn't available (patches welcome).
  2. This functionality isn't available (patches welcome).
  3. This functionality isn't available (patches welcome).
  4. See the sparse documentation for ?addTA, specifically the on argument.
  5. Plot the bottom chart as two separate up/down series, using two different colors, or perhaps chartTheme.
  6. Not sure what you mean; just don't plot the bottom chart...
  7. See the sparse documentation for the major.ticks argument to chartSeries. I don't think you can change the y axis grid line spacings, and the x axis spacing will be the same for the top and bottom chart.
  8. See ?png and ?pdf.
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
2

To change or remove the bottom chart, check the TA argument of chartSeries function (there is an example in the manual); to change the colours, check the theme argument (there is an example in the manual); to write to a png or pdf file, use the png or pdf functions, as with other plotting functions.

To fine-tune the axes and labels, it is probably easier to bypass chartSeries altogether and plot the data yourself, with base graphics, lattice or ggplot2.

Vincent Zoonekynd
  • 31,893
  • 5
  • 69
  • 78
  • 1
    The problem with bypassing ChartSeries is that some very useful functionality (such as candlesticks) is not in any other package (AFAIK). – Darren Cook Feb 06 '12 at 13:19