[R-SIG-Finance] How to Draw a Candle Chart using ggplot2?

Hsiao-nan Cheung niheaven at gmail.com
Mon Feb 22 07:10:36 CET 2016

Dear All,

Recently I tried to plot a candle chart using package ggplot2, and have
tried geom_boxplot function, but here I have some problems. Since a candle
chart haven't a middle bar, when I use stat = "identity" to set the single
candle's border of a candle chart, I want to ignore the middle param of a
boxplot. But in recent ggplot2 version (2.0), in geom_boxplot's aesthetics,
the middle param is required, and I cannot give it a NA value to ommit it
as early version. My solution now is set middle = lower, but this would
lead to a VERY strong lower bar. So is there any suggestion that can meet
my requirement?

My sessionInfo()

R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggplot2_2.0.0 RevoUtilsMath_3.2.3

loaded via a namespace (and not attached):
[1] colorspace_1.2-6 scales_0.3.0 plyr_1.8.3 rsconnect_0.3.79 tools_3.2.3
[6] gtable_0.1.2 Rcpp_0.12.2 grid_3.2.3 munsell_0.4.2

btw, my data's data.frame has two column to indecate the single boxplot's
color and fill, but ggplot2 will treat it as some factors. For example, if
I set somedata[1, "Color"] = "red" and somedata[1, "Fill"] = "red",
and set colour
= Color, fill = Fill in geom_boxplot's aes arg, the plot may show me a
green box... How to define the colour and fill in the data.frame directly?

Hsiao-nan Cheung

	[[alternative HTML version deleted]]

More information about the R-SIG-Finance mailing list