Override variable width geom_bar when used with continuous variables on x and y

41 views
Skip to first unread message

David Johnston

unread,
Sep 10, 2012, 8:20:53 PM9/10/12
to ggp...@googlegroups.com

Hi!

 

For the following, hopefully self-contained, data+plot (attached PDF), I am wondering whether the width of each of the bars can be made constant.  Notice in the upper facet panel the green bar is considerably thicker than the red and blue bars.  I am also wondering whether it is possible to add a gap between the two bars in the lower facet (for example, the ones to the far left).  A very small one but enough to help visually distinguish between the two.  The reason they are touching is because they share the exact same parameters and so the “dodge” algorithm kicks in.

 

Thanks!

 

David J.

 

Version: ggplot2_0.9.1

 

Dput:

 

structure(list(desc.cat = structure(c(4L, 3L, 2L, 1L, 4L, 3L,

2L, 1L, 4L, 3L, 2L, 1L), .Label = c("MUGT70", "MU6070", "MULT60",

"UC500"), class = "factor"), Model = structure(c(1L, 1L, 1L,

1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("Original", "Final",

"Reference"), class = "factor"), mu = c(1.14, 1.29, 1.67, 2,

1.14, 1.19, 1.68, 1.98, 1.35, 1.4, 1.67, 2), cp = c(0.35, 0.35,

0.22, 0.08, 0.35, 0.16, 0.12, 0.37, 0.1, 0.15, 0.25, 0.5), comp = c(0.399,

0.4515, 0.3674, 0.16, 0.399, 0.1904, 0.2016, 0.7326, 0.135, 0.21,

0.4175, 1)), .Names = c("desc.cat", "Model", "mu", "cp", "comp"

), row.names = c(NA, -12L), class = "data.frame")

 

/Dput

 

Plot:

 

ggplot(priceBandData) +

                theme_bw() +

                geom_bar(

                                aes(

                                                y=cp

                                                , x=mu

                                                , fill=Model

                                )

                                , position=position_dodge()

                                , stat="identity"

                ) + facet_grid(desc.cat~.)

 

 

PriceBand_Hybrid.pdf

Winston Chang

unread,
Sep 11, 2012, 10:52:08 AM9/11/12
to David Johnston, ggp...@googlegroups.com
When dodging, ggplot fits the bars into the original width. The best thing I can think of is to adjust the x values in your data before sending it to ggplot.

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages