0

I try creating a dual chart of column and line chart from a table, but the second chart which is the line graph failed to work as I wanted, I can hardly see it on its own trend. Below is the code sample and the plotted chart

ggplot(month_group) + 
  geom_col(aes(x = order_month, y = Total_sales), size = 1, color = "darkblue", fill = "white") +
  geom_line(aes(x = order_month, y = order_per_month), size = 1.5, color="red", group = 1) +
  scale_y_continuous(sec.axis=sec_axis(~.* 0.008,name="order_per_month"))

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 1
    The issue is that you also have to transform your data not just the range of the scale, i.e. try `geom_line(aes(x = order_month, y = order_per_month / .008)`. See e.g. [this](https://r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html) or [this related SO post](https://stackoverflow.com/questions/3099219/ggplot-with-2-y-axes-on-each-side-and-different-scales). – stefan Nov 02 '22 at 07:02

0 Answers0