Creating a dual y-axis one on top of each other












-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










share|improve this question




















  • 1




    looks like multiple plot panes. See facet_wrap e.g. plot.ly/ggplot2/facet_wrap
    – Jonny Phelps
    Nov 23 '18 at 11:26










  • Your data is not time-series data. You will need to provide more information/context on what you are trying to achieve.
    – hrbrmstr
    Nov 23 '18 at 13:20










  • Sorry I copied the wrong data. I re-posted the one with time series and that should better reflect the graph.
    – Eliel Epelbaum
    Nov 23 '18 at 13:33
















-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










share|improve this question




















  • 1




    looks like multiple plot panes. See facet_wrap e.g. plot.ly/ggplot2/facet_wrap
    – Jonny Phelps
    Nov 23 '18 at 11:26










  • Your data is not time-series data. You will need to provide more information/context on what you are trying to achieve.
    – hrbrmstr
    Nov 23 '18 at 13:20










  • Sorry I copied the wrong data. I re-posted the one with time series and that should better reflect the graph.
    – Eliel Epelbaum
    Nov 23 '18 at 13:33














-1












-1








-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










share|improve this question















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







r ggplot2 graph






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 13:32

























asked Nov 23 '18 at 11:11









Eliel Epelbaum

135




135








  • 1




    looks like multiple plot panes. See facet_wrap e.g. plot.ly/ggplot2/facet_wrap
    – Jonny Phelps
    Nov 23 '18 at 11:26










  • Your data is not time-series data. You will need to provide more information/context on what you are trying to achieve.
    – hrbrmstr
    Nov 23 '18 at 13:20










  • Sorry I copied the wrong data. I re-posted the one with time series and that should better reflect the graph.
    – Eliel Epelbaum
    Nov 23 '18 at 13:33














  • 1




    looks like multiple plot panes. See facet_wrap e.g. plot.ly/ggplot2/facet_wrap
    – Jonny Phelps
    Nov 23 '18 at 11:26










  • Your data is not time-series data. You will need to provide more information/context on what you are trying to achieve.
    – hrbrmstr
    Nov 23 '18 at 13:20










  • Sorry I copied the wrong data. I re-posted the one with time series and that should better reflect the graph.
    – Eliel Epelbaum
    Nov 23 '18 at 13:33








1




1




looks like multiple plot panes. See facet_wrap e.g. plot.ly/ggplot2/facet_wrap
– Jonny Phelps
Nov 23 '18 at 11:26




looks like multiple plot panes. See facet_wrap e.g. plot.ly/ggplot2/facet_wrap
– Jonny Phelps
Nov 23 '18 at 11:26












Your data is not time-series data. You will need to provide more information/context on what you are trying to achieve.
– hrbrmstr
Nov 23 '18 at 13:20




Your data is not time-series data. You will need to provide more information/context on what you are trying to achieve.
– hrbrmstr
Nov 23 '18 at 13:20












Sorry I copied the wrong data. I re-posted the one with time series and that should better reflect the graph.
– Eliel Epelbaum
Nov 23 '18 at 13:33




Sorry I copied the wrong data. I re-posted the one with time series and that should better reflect the graph.
– Eliel Epelbaum
Nov 23 '18 at 13:33












1 Answer
1






active

oldest

votes


















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






share|improve this answer

















  • 1




    Thank you! That works!
    – Eliel Epelbaum
    Nov 23 '18 at 21:13











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445601%2fcreating-a-dual-y-axis-one-on-top-of-each-other%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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






share|improve this answer

















  • 1




    Thank you! That works!
    – Eliel Epelbaum
    Nov 23 '18 at 21:13
















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






share|improve this answer

















  • 1




    Thank you! That works!
    – Eliel Epelbaum
    Nov 23 '18 at 21:13














0












0








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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 17:07









TJ83

614




614








  • 1




    Thank you! That works!
    – Eliel Epelbaum
    Nov 23 '18 at 21:13














  • 1




    Thank you! That works!
    – Eliel Epelbaum
    Nov 23 '18 at 21:13








1




1




Thank you! That works!
– Eliel Epelbaum
Nov 23 '18 at 21:13




Thank you! That works!
– Eliel Epelbaum
Nov 23 '18 at 21:13


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445601%2fcreating-a-dual-y-axis-one-on-top-of-each-other%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks