-1

I am trying to create in R a graph with Dual y-axis similar to the graph below. Is there such option? In ggplot2? Thank you for your help!

Data: structure(list(Month = structure(c(16071, 16102, 16130, 16161, 16191, 16222, 16252, 16283, 16314, 16344, 16375, 16405, 16436, 16467, 16495, 16526, 16556, 16587, 16617, 16648, 16679, 16709, 16740, 16770, 16801, 16832, 16861, 16892, 16922, 16953, 16983, 17014, 17045, 17075, 17106, 17136, 17167, 17198, 17226, 17257, 17287, 17318, 17348, 17379, 17410, 17440, 17471, 17501), class = "Date"), Year = c(2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017 ), Sales = c(268377, 84235, 392020, 270706, 273254, 22255, 386118, 23253, 65497, 106306, 123331, 385079, 186158, 146892, 237677, 158845, 125116, 16009, 217467, 227434, 95821, 30820, 22241, 261339, 217884, 49189, 217724, 450000, 102882, 304524, 328485, 166489, 236167, 227174, 55794, 362478, 48639, 83485, 3320, 348728, 178646, 390000, 98342, 225186, 114795, 168494, 349530, 275178), moving_average_of_sales = c(227337, 226970, 232838.6, 249849.3, 251940.8, 221772.2, 240692.5, 216177.9, 214923.1, 189202.1, 174697.5, 204781.9, 184195.7, 171814.3, 168256.6, 181915.6, 155815.4, 155091, 170288, 182400.8, 179649.8, 144223.9, 127832.2, 139276.9, 137297.6, 126332, 135592.8, 178991.9, 167533.4, 175242.4, 198508.8, 212075.7, 233468.3, 230051.8, 213842.8, 245171.7, 228263.2, 191611.7, 181655.5, 186075.9, 171092, 193443.1, 179660.6, 179461.8, 185361.9, 165963.5, 196052.6, 215221.9)), row.names = c(NA, 48L), class = "data.frame")

enter image description here

1 Answers1

0

I usually use ggarrange from ggpubr. If you save the 2 plots as p1 and p2 then

ggpubr::ggarrange(p1, p2, nrow = 2, align = "v")

https://stackoverflow.com/a/48004459/9517359

TJ83
  • 71
  • 4