[R] ggplot2: formula for bar width in geom_bar?
J Toll
jctoll at gmail.com
Thu Mar 1 23:46:46 CET 2012
Hi,
I'm trying to figure out the formula used by ggplot2 to calculate the
width of a bar in geom_bar so that I can use that elsewhere in the
plot. My code looks like this:
ggplot(xAll, aes(Date)) +
geom_bar(subset = .(Direction == "Up"), aes(y = Change, fill =
Time), stat = "identity") +
geom_bar(subset = .(Direction == "Down"), aes(y = Change, fill =
Time), stat = "identity") +
geom_segment(data = xline,
aes(Date, Total,
xend = Date,
yend = (Total - (sign(Total) * (mean(Total)/25)))),
size = 5, # this is where I need to substitute in
the geom_bar width
color = "white")
Right now, I have to manually adjust (i.e. guess) the size of
geom_segment so that it matches the width of geom_bar. Can someone
point me to the formula used by geom_bar to calculate bar width? I've
attached an example plot for reference.
Thanks,
James
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bar_plot.png
Type: image/png
Size: 23728 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120301/348fbfd7/attachment.png>
More information about the R-help
mailing list