I'm trying to figure out how to draw a line between dodged the geometry within ggplot.
I would like a line connecting the tops of the bars (or other geometry) that is being dodged using position_dodge()
Here is an example using mtcars
I would like that line to connect the tops of the bars within a single gear group.
However, if I only specify a position_dodge for the geom_line() the resulting line connects the top of the carb levels.
ggplot(
data = mtcars,
aes(
x=gear,
y=cyl,
group=carb
)
)+
geom_col(
position = position_dodge(width = 0.9)
)+
geom_line(
position = position_dodge(width = 0.9)
)
Specifying gear as the grouping within geom_line(), resulting in just a single vertical line.
ggplot(
data = mtcars,
aes(
x=gear,
y=cyl,
group=carb
)
)+
geom_col(
position = position_dodge(width = 0.9)
)+
geom_line(
aes(
group=gear
),
position = position_dodge(width = 0.9)
)



