Announcement

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

  • Question about graph bar x axis labels

    Dear scientists,

    My idea is to make label of x axis tilt 45°, but when I run my code as below, there is an error. (Data is the sysuse auto)
    Would you please help me to correct code below and get the tilting x axis label?

    Thansk!

    Jack

    My code and error:

    Code:
    sysuse auto, clear
    graph bar rep78, over(foreign) xla(angle(45))
    xlabels(angle(45)) not allowed, xaxis1 does not exist
    r(198);
    Last edited by Liang Wang Jack; 04 Jul 2017, 21:49.

  • #2
    Here's the correct code:

    Code:
    sysuse auto, clear
    graph bar rep78, over(foreign, lab(angle(45))) graphregion(col(white)) ylab(,angle(0))
    I have no idea what you want to do this though; now I have to tilt my head to read the labels

    Comment


    • #3
      Originally posted by Chris Larkin View Post
      Here's the correct code:

      Code:
      sysuse auto, clear
      graph bar rep78, over(foreign, lab(angle(45))) graphregion(col(white)) ylab(,angle(0))
      I have no idea what you want to do this though; now I have to tilt my head to read the labels
      Thank you very much! I tilt my head now.

      Comment


      • #4
        If you use graph hbar instead of graph bar you don't have to tilt your head.
        Code:
        graph hbar rep78, over(foreign)

        Comment


        • #5
          how do I have a common y-label instead of suppressing all. I want the race to be displayed only in the first graph.

          use http://www.stata-press.com/data/r14/nlswork

          graph hbar tenure hours wks_work if age < 16, ///
          over(race, label(labstyle()) ) ///
          by(age, style(combine) row(1) norescale edgelabel iylabel noiytitle iytick noiyaxes) ///
          legend(label (1 "tenure") label (2 "hours") label (3 "wks_work") row(1)) ///
          ysize(2) name(a, replace)
          Click image for larger version

Name:	aa.png
Views:	4
Size:	73.0 KB
ID:	1641829

          Comment


          • #6
            bibha dhungel You posted the same question several times in as many minutes. That won't increase the chance of your getting a good answer. It does increase the chance of your wasting people's time. Please don't do this! The FAQ Advice explains why not.

            This is often discussed here. See the recent thread https://www.statalist.org/forums/for...s-in-by-graphs for the best discussion I can recall right now.

            Your example shows the graphical issue clearly. It can't be taken seriously otherwise as tenure is essentially invisible given differing units, and for other reasons.

            If you posted an example based on what you want to do with your real data, you might get more direct advice.
            Last edited by Nick Cox; 21 Dec 2021, 08:44.

            Comment


            • #7
              Thanks for your help Nick Cox and I will keep in mind not to repeat the same post next time. My last two posts were unanswered for a very long time and I really needed an answer for this problem, I thus posted in multiple places.

              I found another post that suggests graph dot but I wanted it to be a graph bar. But seems like there is no other option and I would have to create my graph with manual manipulations.

              Post 3 here also provides a way, but it is too much of a workaround for a simple graph.

              I wanted to make the following graph, and want just the first graph to have y-axis label (which is the suicide method). (In this example I suppressed all y-axis labels so that I can manually add them later in the Word file). The bars represent the absolute change in rates of suicide mortality between 2001-2004 and 2015-2018. The graph is made separately by age group.
              Click image for larger version

Name:	women.jpg
Views:	1
Size:	95.1 KB
ID:	1641920


              Comment


              • #8
                bibha dhungel Thanks for your reply. I can't add helpfully except to say that a graph such as you want is possible but not trivial with twoway bar

                Some of the needed tricks are covered in threads you have posted in, but I can't suggest precise code on this information. In any case it seems that you have resolved to do the final editing outside Stata.

                Comment


                • #9
                  Hey everybody,

                  i made a stacked bar chart (percentage) of 7 categorial variables und would like to add %-Signs to the bar without using the graph editor, is there any way to do it with code?
                  Here´s my code für data and graph:

                  foreach var of varlist (Q603_1_N - Q603_7_N) {
                  recode `var' 3=1 1=2 6=3 2=4 5=5 4=6
                  }

                  mvdecode Q603_1_N - Q603_7_N, mv (6=.a)

                  foreach var of varlist (Q603_1_N - Q603_7_N) {
                  label define `var' 1 "gut" 2 "eher gut" 3 "teils, teils" ///
                  4 "eher schlecht" 5 "schlecht", modify
                  }


                  * Vorbereitung für Grafik
                  clonevar ta1= Q603_1_N
                  clonevar ta2= Q603_2_N
                  clonevar ta3= Q603_3_N
                  clonevar ta4= Q603_4_N
                  clonevar ta5= Q603_5_N
                  clonevar ta6= Q603_6_N
                  clonevar ta7= Q603_7_N

                  local ta1: var lab ta1
                  dis "`ta1`"
                  foreach var of varlist _all {
                  local `var`: var lab `var`
                  }


                  gen id = _n
                  reshape long ta, i(id)
                  rename ta score
                  *-------------------------------------------------------------------------------------------------------------------------
                  set scheme myscheme1
                  graph set window fontface "Franklin Gothic Book"
                  graph hbar (percent) if BundeslandAdressinformation== "Nordrhein-Westfalen" , over (score) over(_j, relabel ///
                  (1 "Werdende Eltern" 2 "Paarfamilien (Familien mit zwei Elternteilen)" 3 "Alleinerziehende (Familien mit einem Elternteil)" ///
                  4 "Familien mit Migrationshintergrund" 5 "Personen in Trennung/Scheidung" 6 "Sozial schwache Familien" ///
                  7 "Familien mit wenig Internetkenntnissen")) asyvars percentage stack ///
                  blabel(bar, pos(center) size(2.5) color(white) format(%2.0f)) ytitle("") ylabel( 0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%") ///
                  title("") legend(pos(bottom) cols(5)) name(graph1, replace) xsize(7)
                  *---------------------------------------------------------------------------------------------------------------------------------------------------------------

                  thanks a lot und beste regards, Tim

                  Comment


                  • #10
                    The question posed in #9 has been started as a new discussion here: https://www.statalist.org/forums/for...cked-bar-chart

                    Interested readers should follow it there.

                    Comment

                    Working...
                    X