0

I try to use ggplot in Python. But I have a problem with plotting second axis on the right. Now I generate such image enter image description here

with code:

(
    ggplot(t, aes('app_dt', y='distr', fill='temp')) \
    + geom_col() \
    + geom_line(t, aes('app_dt', y=..., group=1), colour='red') \
    + geom_point(t, aes('app_dt', y=...), size=2, fill='white') \
    + geom_text(...) \
    + scale_y_continuous(label='percent') \
    + geom_text(aes(label=round(t['distr'] * 100, 1).astype(str) + '%'), size=7, position=position_stack(vjust=0.5)) \
    + scale_fill_brewer(palette='PuBuGn')
)

But I need something like this enter image description here

So the questions are:

  1. How I can add second axis, which values are connected with persent values in the red (blue) line?

  2. Which function I should use to change color pallete to custom?

  3. How I can make percent scale for axises?

Thank you in advance!

  • https://stackoverflow.com/a/53703152/10580543 check this for adding a second axis on the right with ggplot. In addition you can manually set the color using `scale_fill_manual` instead of `scale_fill_brewer` – tom Dec 04 '19 at 10:50
  • I searched and found that in R second and first axises, provided by ggplot, had to be connected with some formula. what is more, this R function didn't work for me: scale_y_continuous(labels = scales::percent, sec.axis = sec_axis(~. * psi_plot_lim, labels = scales::percent)) so the question was opened. – Любовь Пономарева Dec 04 '19 at 10:54
  • I mean I don't have option sec.axis in Python – Любовь Пономарева Dec 04 '19 at 11:00

0 Answers0