Announcement

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

  • please help. making bar graph more simple with "over" options

    Hi, guys.

    I'm a newcomers with stata, and there is some trouble in making bar graph.

    My data has 46 observations, and it has numeric variable for displaying year-month.

    here is some code i had run:

    Code:
    graph bar fluct, over(year, label(labsize(vsmall) angle(45)))    /// 
        blabel(bar, size(vsmall) format(%9.1f)    ///
        )    ///
        ytitle("Fluctuation") graphregion(color(white))

    and the graph it produces:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	70.4 KB
ID:	1690605



    Four problems I want to solve:

    1) The x-axis labels are too many so I want to display some labels (e.g. 201910, 202010, 202110, 202210). this graph aims to show that the fluctuation along specific month by year.

    2) Similar with problem 1), I want to display some bar labels only ("blabel" option).

    3) some bar labels are overlapped. I want to show it not overlapping

    4) I want to coloring only last one.


    I attach the data here. please some help.


    Attached Files

  • #2
    Welcome to Statalist, TaeJun! Please go through the advice in the Statalist FAQ, especially section 12, on how best to post questions to the list. In particular, please post a data extract using the dataex command in Stata (and not your Stata dataset), to help others respond to your query. People are usually unwilling to open files from unknown sources.

    Comment


    • #3
      Cross-posted in slightly different form at https://www.reddit.com/r/stata/comme...h_over_option/

      Please note our policy on cross-posting, which is that you are asked to tell us about it.

      A short answer is that you need

      Code:
      twoway bar
      not

      Code:
      graph bar
      for what you want, and that you will get more flexibility with

      Code:
      gen mdate = ym(floor(year/100), mod(year, 100)) 
      
      format mdate %tm
      A longer answer is given within https://journals.sagepub.com/doi/10....6867X211000032 and the title

      Stata tip 140: Shorter or fewer category labels with graph bar

      shows its focus on your question.

      Comment


      • #4
        I had cross-posted this post at https://www.reddit.com/r/stata/comme...h_over_option/

        and, Now I solved this problem.

        I produced this graph:

        Click image for larger version

Name:	under300.png
Views:	1
Size:	35.8 KB
ID:	1690629


        It is the graph exactly what I want. I solved it an way that overlay three graph.

        Here some code and data I used(check attachment):

        Code:
        twoway bar fluct time, barw(.6) ///
            xlabel(10(12)58, angle(45) valuelabel labsize(vsmall)) ylabel(, labsize(*0.5)) ///
            graphregion(color(white)) ///
            ytitle("") xtitle("") || ///
            bar fluct time if time == 10 | time == 22 | time == 34 | time == 46 | time == 58, barw(.6) /// 
            color(red) legend(off) || ///
            scatter fluct time if time == 10 | time == 22 | time == 34 | time == 46 | time == 58, ///
            mlabel(fluct) mlabpos(12) mlabsize(vsmall) mlabf(%9.1f) msymbol(none) mlabcolor(black) ///
            title("")
        Attached Files

        Comment

        Working...
        X