How to get percentages on the y axes in an alluvial or sankey plot?

后端 未结 3 960
眼角桃花
眼角桃花 2021-01-16 02:53

I realized this graph using ggplot2 and I\'d like to change y axes to percentages, from 0% to 100% with breaks every 10. I know I can use:

+ scale_y         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-16 03:33

    Simply normalising your y-values seems to do the trick:

    library(ggplot2)
    
    ggplot(mtcars, aes(x = cyl, y = mpg/max(mpg))) +
      geom_point() +
      scale_y_continuous(label = scales::label_percent())
    

    Created on 2020-05-19 by the reprex package (v0.3.0)

提交回复
热议问题