missing yearmon labels using ggplot scale_x_yearmonHow to display the December in xaxis when using autoplot and yearmonRotating and spacing axis labels in ggplot2working with months in zooPlotting monthly data with ggplotggplot2 stats=“identity” and stacking colors in bar plot gives “striped” bar chartBarplot without lexicographical order in ggplotggplot geom_text not seating on top of barsggplot: line plot for discrete x-axisConverting a factor time variable to yearmon variableHow to reorder the groups in a grouped bar-chartsort by month and year R

Why didn’t Eve recognize the little cockroach as a living organism?

How were servants to the Kaiser of Imperial Germany treated and where may I find more information on them

Isometric embedding of a genus g surface

Origin of pigs as a species

How to get directions in deep space?

Storage of electrolytic capacitors - how long?

Review your own paper in Mathematics

How to I force windows to use a specific version of SQLCMD?

What is this high flying aircraft over Pennsylvania?

What should be the ideal length of sentences in a blog post for ease of reading?

Overlapping circles covering polygon

Would a primitive species be able to learn English from reading books alone?

If Captain Marvel (MCU) were to have a child with a human male, would the child be human or Kree?

Are inadvertent environmental catastrophes also examples of natural selection?

Why is the principal energy of an electron lower for excited electrons in a higher energy state?

Why is the sun approximated as a black body at ~ 5800 K?

How do you justify more code being written by following clean code practices?

How many people need to be born every 8 years to sustain population?

How to preserve electronics (computers, iPads and phones) for hundreds of years

Given this phrasing in the lease, when should I pay my rent?

Animation: customize bounce interpolation

Do I have to take mana from my deck or hand when tapping a dual land?

What happens if I try to grapple mirror image?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?



missing yearmon labels using ggplot scale_x_yearmon


How to display the December in xaxis when using autoplot and yearmonRotating and spacing axis labels in ggplot2working with months in zooPlotting monthly data with ggplotggplot2 stats=“identity” and stacking colors in bar plot gives “striped” bar chartBarplot without lexicographical order in ggplotggplot geom_text not seating on top of barsggplot: line plot for discrete x-axisConverting a factor time variable to yearmon variableHow to reorder the groups in a grouped bar-chartsort by month and year R













1















I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?



Example data:



df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
df$dates <- as.yearmon(df$dates)

ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_yearmon(format="%Y %m")


enter image description here










share|improve this question


























    1















    I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?



    Example data:



    df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
    df$dates <- as.yearmon(df$dates)

    ggplot(df, aes(x = dates, y = values)) +
    geom_bar(position="dodge", stat="identity") +
    theme_light() +
    xlab('Month') +
    ylab('values')+
    scale_x_yearmon(format="%Y %m")


    enter image description here










    share|improve this question
























      1












      1








      1








      I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?



      Example data:



      df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
      df$dates <- as.yearmon(df$dates)

      ggplot(df, aes(x = dates, y = values)) +
      geom_bar(position="dodge", stat="identity") +
      theme_light() +
      xlab('Month') +
      ylab('values')+
      scale_x_yearmon(format="%Y %m")


      enter image description here










      share|improve this question














      I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?



      Example data:



      df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
      df$dates <- as.yearmon(df$dates)

      ggplot(df, aes(x = dates, y = values)) +
      geom_bar(position="dodge", stat="identity") +
      theme_light() +
      xlab('Month') +
      ylab('values')+
      scale_x_yearmon(format="%Y %m")


      enter image description here







      r ggplot2 graph zoo






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 8 at 11:38









      Dom BurnsDom Burns

      400415




      400415






















          2 Answers
          2






          active

          oldest

          votes


















          2














          I think scale_x_yearmon was meant for xy plots as it calls scale_x_continuous but we can just call scale_x_continuous ourselves like this (only the line marked ## is changed):



          ggplot(df, aes(x = dates, y = values)) + 
          geom_bar(position="dodge", stat="identity") +
          theme_light() +
          xlab('Month') +
          ylab('values')+
          scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##


          screenshot






          share|improve this answer






























            0














            I think it's an issue with plotting zoo objects. Use the standard Date class and specify the date label in ggplot. You'll need to add the day into the character string for your dates column. Then you can use scale_x_date and specify the date_labels.



            library(tidyverse)
            df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
            arrange(dates) %>%
            mutate(dates = as.Date(paste0(dates, "-01")))


            ggplot(df, aes(x = dates, y = values)) +
            geom_bar(position="dodge", stat="identity") +
            scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
            theme_light() +
            xlab('Month') +
            ylab('values')


            result plot






            share|improve this answer























            • It is not an issue with plotting zoo objects. There are no zoo objects in this problem.

              – G. Grothendieck
              Feb 8 at 12:16











            • Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output

              – nycrefugee
              Feb 8 at 12:27










            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%2f54591625%2fmissing-yearmon-labels-using-ggplot-scale-x-yearmon%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            I think scale_x_yearmon was meant for xy plots as it calls scale_x_continuous but we can just call scale_x_continuous ourselves like this (only the line marked ## is changed):



            ggplot(df, aes(x = dates, y = values)) + 
            geom_bar(position="dodge", stat="identity") +
            theme_light() +
            xlab('Month') +
            ylab('values')+
            scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##


            screenshot






            share|improve this answer



























              2














              I think scale_x_yearmon was meant for xy plots as it calls scale_x_continuous but we can just call scale_x_continuous ourselves like this (only the line marked ## is changed):



              ggplot(df, aes(x = dates, y = values)) + 
              geom_bar(position="dodge", stat="identity") +
              theme_light() +
              xlab('Month') +
              ylab('values')+
              scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##


              screenshot






              share|improve this answer

























                2












                2








                2







                I think scale_x_yearmon was meant for xy plots as it calls scale_x_continuous but we can just call scale_x_continuous ourselves like this (only the line marked ## is changed):



                ggplot(df, aes(x = dates, y = values)) + 
                geom_bar(position="dodge", stat="identity") +
                theme_light() +
                xlab('Month') +
                ylab('values')+
                scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##


                screenshot






                share|improve this answer













                I think scale_x_yearmon was meant for xy plots as it calls scale_x_continuous but we can just call scale_x_continuous ourselves like this (only the line marked ## is changed):



                ggplot(df, aes(x = dates, y = values)) + 
                geom_bar(position="dodge", stat="identity") +
                theme_light() +
                xlab('Month') +
                ylab('values')+
                scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##


                screenshot







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 8 at 12:09









                G. GrothendieckG. Grothendieck

                153k10135243




                153k10135243























                    0














                    I think it's an issue with plotting zoo objects. Use the standard Date class and specify the date label in ggplot. You'll need to add the day into the character string for your dates column. Then you can use scale_x_date and specify the date_labels.



                    library(tidyverse)
                    df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
                    arrange(dates) %>%
                    mutate(dates = as.Date(paste0(dates, "-01")))


                    ggplot(df, aes(x = dates, y = values)) +
                    geom_bar(position="dodge", stat="identity") +
                    scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
                    theme_light() +
                    xlab('Month') +
                    ylab('values')


                    result plot






                    share|improve this answer























                    • It is not an issue with plotting zoo objects. There are no zoo objects in this problem.

                      – G. Grothendieck
                      Feb 8 at 12:16











                    • Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output

                      – nycrefugee
                      Feb 8 at 12:27















                    0














                    I think it's an issue with plotting zoo objects. Use the standard Date class and specify the date label in ggplot. You'll need to add the day into the character string for your dates column. Then you can use scale_x_date and specify the date_labels.



                    library(tidyverse)
                    df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
                    arrange(dates) %>%
                    mutate(dates = as.Date(paste0(dates, "-01")))


                    ggplot(df, aes(x = dates, y = values)) +
                    geom_bar(position="dodge", stat="identity") +
                    scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
                    theme_light() +
                    xlab('Month') +
                    ylab('values')


                    result plot






                    share|improve this answer























                    • It is not an issue with plotting zoo objects. There are no zoo objects in this problem.

                      – G. Grothendieck
                      Feb 8 at 12:16











                    • Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output

                      – nycrefugee
                      Feb 8 at 12:27













                    0












                    0








                    0







                    I think it's an issue with plotting zoo objects. Use the standard Date class and specify the date label in ggplot. You'll need to add the day into the character string for your dates column. Then you can use scale_x_date and specify the date_labels.



                    library(tidyverse)
                    df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
                    arrange(dates) %>%
                    mutate(dates = as.Date(paste0(dates, "-01")))


                    ggplot(df, aes(x = dates, y = values)) +
                    geom_bar(position="dodge", stat="identity") +
                    scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
                    theme_light() +
                    xlab('Month') +
                    ylab('values')


                    result plot






                    share|improve this answer













                    I think it's an issue with plotting zoo objects. Use the standard Date class and specify the date label in ggplot. You'll need to add the day into the character string for your dates column. Then you can use scale_x_date and specify the date_labels.



                    library(tidyverse)
                    df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
                    arrange(dates) %>%
                    mutate(dates = as.Date(paste0(dates, "-01")))


                    ggplot(df, aes(x = dates, y = values)) +
                    geom_bar(position="dodge", stat="identity") +
                    scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
                    theme_light() +
                    xlab('Month') +
                    ylab('values')


                    result plot







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 8 at 12:01









                    nycrefugeenycrefugee

                    764418




                    764418












                    • It is not an issue with plotting zoo objects. There are no zoo objects in this problem.

                      – G. Grothendieck
                      Feb 8 at 12:16











                    • Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output

                      – nycrefugee
                      Feb 8 at 12:27

















                    • It is not an issue with plotting zoo objects. There are no zoo objects in this problem.

                      – G. Grothendieck
                      Feb 8 at 12:16











                    • Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output

                      – nycrefugee
                      Feb 8 at 12:27
















                    It is not an issue with plotting zoo objects. There are no zoo objects in this problem.

                    – G. Grothendieck
                    Feb 8 at 12:16





                    It is not an issue with plotting zoo objects. There are no zoo objects in this problem.

                    – G. Grothendieck
                    Feb 8 at 12:16













                    Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output

                    – nycrefugee
                    Feb 8 at 12:27





                    Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output

                    – nycrefugee
                    Feb 8 at 12:27

















                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54591625%2fmissing-yearmon-labels-using-ggplot-scale-x-yearmon%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

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved