Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graph format

    Hi,

    I recently noticed that in my every graph the alignment of x and y-axis values are not align properly and even if i change the font size it doesn't reflect the changes (see attached for reference).

    would be really appreciate for your support.

    here is the simple Stata code i used to generate this plot:

    graph bar (sum) g if iso3=="KEN", over(hazardtype) over(year, label(labsize(medium))) asyvars stack ///
    ytitle("Total Number of Disaster Internal Displacements") ylabel(, labsize(medium)) title("Kenya", size(large)) ///
    subtitle("Number of Disaster Internal Displacements") legend(position(11) ring(0))



    Thanks,
    Muhammad
    Attached Files
    Last edited by Muhammad Islam; 31 Mar 2025, 09:58.

  • #2
    You may need the extra option nofill.

    Comment


    • #3
      Hi Nick,

      Thanks for your response. I tried with nofill but the same issue. it look like some some setting has been altered by default since even for a simple stack bar chart with the following code the plot is completely out of alignment.

      graph bar (sum) g if iso3=="KEN", nofill over(hazardtype) over(year, label(labsize(medium))) asyvars stack


      is there is any option in Stata where i can set it as default.

      Thanks,
      Muhammad

      Attached Files

      Comment


      • #4
        I think we need a data example so that your code gives a reproducible example. Please copy and paste the results of

        Code:
        dataex  g hazardtype year if iso3=="KEN"
        https://www.statalist.org/forums/help#stata gives more explanation.

        Comment


        • #5
          Hi Nick,

          Here is the output of the code you have given:

          ----------------------- copy starting from the next line -----------------------
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input long g str19 hazardtype int year
            3000 "Flood"         2018
             100 "Flood"         2008
           10000 "Flood"         2008
           33686 "Flood"         2009
           58000 "Flood"         2009
            9516 "Flood"         2010
           44270 "Flood"         2010
            4000 "Flood"         2011
           15045 "Flood"         2011
             912 "Flood"         2012
           96714 "Flood"         2012
            4590 "Flood"         2013
            6000 "Flood"         2013
          169692 "Flood"         2013
             300 "Mass Movement" 2014
            1068 "Flood"         2014
             390 "Flood"         2015
            1170 "Flood"         2015
          103524 "Flood"         2015
           49452 "Flood"         2016
               8 "Flood"         2017
           10000 "Flood"         2017
             312 "Flood"         2017
               8 "Flood"         2017
           24803 "Flood"         2017
             293 "Flood"         2017
             700 "Flood"         2018
            1950 "Storm"         2018
             378 "Flood"         2018
            1950 "Flood"         2018
          326612 "Flood"         2018
             200 "Flood"         2018
             780 "Flood"         2018
               8 "Flood"         2018
             390 "Flood"         2018
             300 "Flood"         2018
               8 "Flood"         2019
             780 "Wildfire"      2019
             437 "Storm"         2019
             156 "Storm"         2019
            1000 "Flood"         2019
             390 "Flood"         2019
             117 "Flood"         2019
             150 "Flood"         2019
           70725 "Flood"         2019
             780 "Mass Movement" 2020
              20 "Mass Movement" 2020
            1170 "Flood"         2020
             702 "Flood"         2020
            1560 "Storm"         2020
          253974 "Flood"         2020
               8 "Flood"         2020
            7800 "Flood"         2020
              18 "Mass Movement" 2020
           30000 "Flood"         2020
             195 "Flood"         2020
           38789 "Flood"         2020
             200 "Flood"         2021
               2 "Drought"       2021
              98 "Storm"         2022
             728 "Flood"         2022
           92352 "Drought"       2022
          183216 "Drought"       2022
             474 "Flood"         2022
           10488 "Drought"       2022
           30150 "Drought"       2022
             255 "Flood"         2023
             364 "Flood"         2023
            2956 "Flood"         2023
              24 "Flood"         2023
             371 "Flood"         2023
             180 "Flood"         2023
           30150 "Flood"         2023
            2000 "Storm"         2023
             312 "Flood"         2023
             600 "Flood"         2023
             600 "Flood"         2023
            3254 "Flood"         2023
           36240 "Flood"         2021
          600000 "Flood"         2023
          end
          ------------------ copy up to and including the previous line ------------------

          Listed 80 out of 338 observations

          Comment


          • #6
            Thanks for the data example. I did this:

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input long g str19 hazardtype int year
              3000 "Flood"         2018
               100 "Flood"         2008
             10000 "Flood"         2008
             33686 "Flood"         2009
             58000 "Flood"         2009
              9516 "Flood"         2010
             44270 "Flood"         2010
              4000 "Flood"         2011
             15045 "Flood"         2011
               912 "Flood"         2012
             96714 "Flood"         2012
              4590 "Flood"         2013
              6000 "Flood"         2013
            169692 "Flood"         2013
               300 "Mass Movement" 2014
              1068 "Flood"         2014
               390 "Flood"         2015
              1170 "Flood"         2015
            103524 "Flood"         2015
             49452 "Flood"         2016
                 8 "Flood"         2017
             10000 "Flood"         2017
               312 "Flood"         2017
                 8 "Flood"         2017
             24803 "Flood"         2017
               293 "Flood"         2017
               700 "Flood"         2018
              1950 "Storm"         2018
               378 "Flood"         2018
              1950 "Flood"         2018
            326612 "Flood"         2018
               200 "Flood"         2018
               780 "Flood"         2018
                 8 "Flood"         2018
               390 "Flood"         2018
               300 "Flood"         2018
                 8 "Flood"         2019
               780 "Wildfire"      2019
               437 "Storm"         2019
               156 "Storm"         2019
              1000 "Flood"         2019
               390 "Flood"         2019
               117 "Flood"         2019
               150 "Flood"         2019
             70725 "Flood"         2019
               780 "Mass Movement" 2020
                20 "Mass Movement" 2020
              1170 "Flood"         2020
               702 "Flood"         2020
              1560 "Storm"         2020
            253974 "Flood"         2020
                 8 "Flood"         2020
              7800 "Flood"         2020
                18 "Mass Movement" 2020
             30000 "Flood"         2020
               195 "Flood"         2020
             38789 "Flood"         2020
               200 "Flood"         2021
                 2 "Drought"       2021
                98 "Storm"         2022
               728 "Flood"         2022
             92352 "Drought"       2022
            183216 "Drought"       2022
               474 "Flood"         2022
             10488 "Drought"       2022
             30150 "Drought"       2022
               255 "Flood"         2023
               364 "Flood"         2023
              2956 "Flood"         2023
                24 "Flood"         2023
               371 "Flood"         2023
               180 "Flood"         2023
             30150 "Flood"         2023
              2000 "Storm"         2023
               312 "Flood"         2023
               600 "Flood"         2023
               600 "Flood"         2023
              3254 "Flood"         2023
             36240 "Flood"         2021
            600000 "Flood"         2023
            end
            
            set scheme stcolor 
            
            graph bar (sum) g, over(hazardtype) over(year, label(labsize(medsm))) asyvars stack ///
            ytitle("Total Number of Disaster Internal Displacements") ylabel(, labsize(medium)) title("Kenya", size(large)) ///
            subtitle("Number of Disaster Internal Displacements") legend(position(11) ring(0))
            Click image for larger version

Name:	kenya.png
Views:	1
Size:	49.1 KB
ID:	1775124


            So, the only change is the size of the year labels. Otherwise I can't reproduce your problem. What graph scheme are you using?

            The graph is puzzling for other reasons. In essence flood dominates all years except 2022, which drought dominates. You are getting stacking of bars
            for the other hazards, but the numbers are so small that the bar segments don't show well. See 2014 for example.

            Comment


            • #7
              I've had this issue when trying to use a font that's not supported.

              Code:
              graph set window fontface "Bad Name"
              
              sysuse auto, clear 
              
              lowess price mpg, title(Some title here)
              To see the list of supported fonts, you should right click on the graph and select "Preferences". There will be a font drop-down box in the dialog that will list all the supported fonts.

              Comment


              • #8
                Hi Nick,

                Thank you so much for your help. I believe there might be an issue with the data reporting for 2022, as the pattern seems different compared to other years. I followed your instructions and ran the exact code you provided, and while the plot should have been generated correctly, I'm still encountering the same issue. It seems to me that I might need to re-install Stata, as some of the graphics settings may have been disrupted.

                Thanks again for your support.

                Best regards,
                Muhammad

                Comment


                • #9
                  Thank you so much Justin,

                  It worked and really surprising i never chose the font just used the default one so don't know how it happened.

                  Thanks,
                  Muhammad

                  Comment


                  • #10
                    You might need a different approach to show all hazards clearly. Here myaxis is from

                    Code:
                    . search myaxis, sj
                    
                    Search of official help files, FAQs, Examples, and Stata Journals
                    
                    SJ-21-3 st0654  . . Speaking Stata: Ordering or ranking groups of observations
                            (help myaxis if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
                            Q3/21   SJ 21(3):818--837
                            discusses procedures for datasets based on aggregate
                            frequencies and for datasets based on individuals and
                            introduce a new convenience command, myaxis, that handles
                            many cases directly
                    Code:
                    * Example generated by -dataex-. For more info, type help dataex
                    clear
                    input long g str19 hazardtype int year
                      3000 "Flood"         2018
                       100 "Flood"         2008
                     10000 "Flood"         2008
                     33686 "Flood"         2009
                     58000 "Flood"         2009
                      9516 "Flood"         2010
                     44270 "Flood"         2010
                      4000 "Flood"         2011
                     15045 "Flood"         2011
                       912 "Flood"         2012
                     96714 "Flood"         2012
                      4590 "Flood"         2013
                      6000 "Flood"         2013
                    169692 "Flood"         2013
                       300 "Mass Movement" 2014
                      1068 "Flood"         2014
                       390 "Flood"         2015
                      1170 "Flood"         2015
                    103524 "Flood"         2015
                     49452 "Flood"         2016
                         8 "Flood"         2017
                     10000 "Flood"         2017
                       312 "Flood"         2017
                         8 "Flood"         2017
                     24803 "Flood"         2017
                       293 "Flood"         2017
                       700 "Flood"         2018
                      1950 "Storm"         2018
                       378 "Flood"         2018
                      1950 "Flood"         2018
                    326612 "Flood"         2018
                       200 "Flood"         2018
                       780 "Flood"         2018
                         8 "Flood"         2018
                       390 "Flood"         2018
                       300 "Flood"         2018
                         8 "Flood"         2019
                       780 "Wildfire"      2019
                       437 "Storm"         2019
                       156 "Storm"         2019
                      1000 "Flood"         2019
                       390 "Flood"         2019
                       117 "Flood"         2019
                       150 "Flood"         2019
                     70725 "Flood"         2019
                       780 "Mass Movement" 2020
                        20 "Mass Movement" 2020
                      1170 "Flood"         2020
                       702 "Flood"         2020
                      1560 "Storm"         2020
                    253974 "Flood"         2020
                         8 "Flood"         2020
                      7800 "Flood"         2020
                        18 "Mass Movement" 2020
                     30000 "Flood"         2020
                       195 "Flood"         2020
                     38789 "Flood"         2020
                       200 "Flood"         2021
                         2 "Drought"       2021
                        98 "Storm"         2022
                       728 "Flood"         2022
                     92352 "Drought"       2022
                    183216 "Drought"       2022
                       474 "Flood"         2022
                     10488 "Drought"       2022
                     30150 "Drought"       2022
                       255 "Flood"         2023
                       364 "Flood"         2023
                      2956 "Flood"         2023
                        24 "Flood"         2023
                       371 "Flood"         2023
                       180 "Flood"         2023
                     30150 "Flood"         2023
                      2000 "Storm"         2023
                       312 "Flood"         2023
                       600 "Flood"         2023
                       600 "Flood"         2023
                      3254 "Flood"         2023
                     36240 "Flood"         2021
                    600000 "Flood"         2023
                    end
                    
                    preserve 
                    
                    collapse (sum) g, by(hazardtype year)
                    
                    fillin hazardtype year
                    
                    replace g = 0 if _fillin 
                    
                    myaxis type=hazardtype, sort(mean g) descending 
                    
                    twoway connected g year, xla(2008(5)2023) ///
                    by(type, l1title("Number of Disaster Internal Displacements") yrescale note("")) sort 
                    
                    restore
                    Click image for larger version

Name:	kenya2.png
Views:	1
Size:	80.4 KB
ID:	1775129

                    Comment

                    Working...
                    X