Graphics Reference
In-Depth Information
Figure 3-14. Left: bar graph with narrow grouped bars; right: with space between the bars
The first graph used position="dodge" , and the second graph used position=posi-
tion_dodge() . This is because position="dodge" is simply shorthand for position=posi-
tion_dodge() with the default value of 0.9, but when we want to set a specific value, we need
to use the more verbose command.
Discussion
The default value of width is 0.9, and the default value used for position_dodge() is the
same. To be more precise, the value of width in position_dodge() is the same as width in
geom_bar() .
All of these will have the same result:
geom_bar(position = "dodge" )
geom_bar(width = 0.9 , position = position_dodge())
geom_bar(position = position_dodge( 0.9 ))
geom_bar(width = 0.9 , position = position_dodge(width = 0.9 ))
The items on the x-axis have x values of 1, 2, 3, and so on, though you typically don't refer to
them by these numerical values. When you use geom_bar(width=0.9) , it makes each group
take up a total width of 0.9 on the x-axis. When you use position_dodge(width=0.9) , it
spaces the bars so that the middleof each bar is right where it would be if the bar width were
0.9 and the bars were touching. This is illustrated in Figure 3-15 . The two graphs both have the
same dodge width of 0.9, but while the top has a bar width of 0.9, the bottom has a bar width of
0.2. Despite the different bar widths, the middles of the bars stay aligned.
Search WWH ::




Custom Search