Here's my data,
year | item | X1 | percent |
---|---|---|---|
2017 | A | 475 | 81.896 |
2017 | B | 580 | 81.896 |
2018 | A | 801 | 71.2 |
2018 | B | 1125 | 71.2 |
2019 | A | 590 | 62.1707 |
2019 | B | 949 | 62.1707 |
2020 | A | 646 | 29.949 |
2020 | B | 2157 | 29.949 |
I tried to make dual y-axis in ggplot,
ggplot(df, aes(x = year, y = X1, fill = item)) +
geom_bar(stat = 'identity', position = 'dodge2') +
geom_line(aes(x = year, y = percent)) +
scale_y_continous(sec.axis = sec_axis(~.*percent, name = "percent"))
but it keeps showing error.
Error: transformation for secondary axes must be monotonic Run `rlang::last_error()` to see where the error occurred.
Here's my graph
I want to make it as dual y-axis(bar graph for X1, line graph for percent). Any help? Thanks!