Announcement

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

  • Vertical Labels

    Hello,
    How do I get the x-axis labels or in this case YearMonth to be vertical?

    Code:
    label var naics_21 "Sector"
    twoway (line TotMonth date, by(naics_21)) (scatter income date, by(naics_21)), legend(label(1 "Total Monthly Hours") label(2 "Total Weekly Income"))
    Thank you,
    Yeshwin

    Click image for larger version

Name:	TimeSeries.jpg
Views:	1
Size:	306.1 KB
ID:	1705986


  • #2
    I think it's
    Code:
    xlab(,angle(45))
    But I'm not at my computer so please don't quote me!

    Comment


    • #3
      A short answer is to use xlabel(, ang(v)) but I think a better answer is to follow procedure suggested in https://www.stata-journal.com/articl...article=gr0030

      You have monthly data for 2019-2022. Here is some technique:

      Code:
      clear
      set obs 48
      gen date = ym(2018, 12) + _n 
      gen foo = 42 
      
      line foo date, xla(713.5 "2019" 725.5 "2020" 737.5 "2021" 749.5 "2022", tlength(*0.5) tlc(none)) xtic(707.5(12)755.5, tlength(*4)) xtitle("")
      Click image for larger version

Name:	betterlabels.png
Views:	1
Size:	10.3 KB
ID:	1705995


      Stuff you can remove as obvious and not needed:

      date

      Graphs by sector


      Plotting your two variables in quite different units in the same space raises various questions, but here I focus on the question you do ask.

      Comment


      • #4
        Originally posted by Jared Greathouse View Post
        I think it's
        Code:
        xlab(,angle(45))
        But I'm not at my computer so please don't quote me!
        Hello Jared, thank you so much for your input
        I was able to use
        Code:
        xlabel(, ang(v))
        to get it to work!

        Comment


        • #5
          Originally posted by Nick Cox View Post
          A short answer is to use xlabel(, ang(v)) but I think a better answer is to follow procedure suggested in https://www.stata-journal.com/articl...article=gr0030

          You have monthly data for 2019-2022. Here is some technique:

          Code:
          clear
          set obs 48
          gen date = ym(2018, 12) + _n
          gen foo = 42
          
          line foo date, xla(713.5 "2019" 725.5 "2020" 737.5 "2021" 749.5 "2022", tlength(*0.5) tlc(none)) xtic(707.5(12)755.5, tlength(*4)) xtitle("")
          [ATTACH=CONFIG]n1705995[/ATTACH]

          Stuff you can remove as obvious and not needed:

          date

          Graphs by sector


          Plotting your two variables in quite different units in the same space raises various questions, but here I focus on the question you do ask.
          Thank you so much for your help Nick! I was able to get it to work. I also plotted separate graphs for the 2 variables. I was just focused on trying to get my code to work, and ended up not realising the error there.

          Comment

          Working...
          X