3

I would like to reproduce the ggplot style of showing a confidence interval around a value with a ribbon, like geom_ribbon or geom_smooth.

I tried calculating the confidence interval separately and plotting with fill_between() which is close but doesn't seem exactly right. How can the x axis be the style that comes from plot_date() while using fill_between()? What about smoothing of the ribbon?

Example output:

enter image description here enter image description here

The ggplot code looks like this (several found examples):

qplot(wt, mpg, data=mtcars, colour=factor(cyl)) +
  geom_smooth(aes(ymin = lcl, ymax = ucl), data=grid, stat="identity")

ggplot(answers.overall, aes(Date, Answers)) + geom_line() + 
  geom_smooth(method="loess") + theme(axis.text.x = element_text(angle = 45, hjust = 1))
Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
Alex I
  • 19,689
  • 9
  • 86
  • 158

1 Answers1

3

Is there a reason why you can't use ggplot for Python? Because that would really simplify things a lot:

import ggplot as gg

mtcars = gg.mtcars
gg.qplot(mtcars.wt, mtcars.mpg) + gg.geom_smooth(color="blue")
Steve S
  • 1,023
  • 7
  • 19
  • 1
    I just wasn't aware that it exists :) Thanks! – Alex I Jun 03 '14 at 08:30
  • 1
    ggplot I think doesn't work with the latest pandas now – Ilaya Raja S Mar 18 '19 at 16:24
  • @IlayaRajaS Thanks for the info. Do you know how long it has been since **ggplot** stopped working? As an aside, one reason I moved away from Python for Data Analysis is because it seemed like every time I'd update my packages something would break. – Steve S Mar 21 '19 at 15:15
  • There is a fix for that ggplot issue, albeit a manual one: https://github.com/yhat/ggpy/issues/662#issuecomment-484138308 – Zak Kann Oct 28 '19 at 23:39