Tom Tom - 1 month ago 4x
R Question

R geom_line not plotting as expected

I am using the following code to plot a stacked area graph and I get the expected plot.

P <- ggplot(DATA2, aes(x=bucket,y=volume, group=model, fill=model,label=volume)) + #ggplot initial parameters
geom_ribbon(position='fill', aes(ymin=0, ymax=1))

area plot no lines

but then when I add lines which are reading the same data source I get misaligned results towards the right side of the graph

P + geom_line(position='fill', aes(group=model, ymax=1))

enter area plot with lines

does anyone know why this may be? Both plots are reading the same data source so I can't figure out what the problem is.


If you switch to using geom_path in place of geom_line, it all seems to work as expected. I don't think the ordering of geom_line is behaving the same as geom_ribbon (and suspect that geom_line -- like geom_area -- assumes a zero base y value)

ggplot(DATA2, aes(x=bucket, y=volume, ymin=0, ymax=1,
                  group=model, fill=model, label=volume)) +
  geom_ribbon(position='fill') +

Should give you

enter image description here