Announcement

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

  • Two line labels (marker or axis labels)

    While doing some -streamplot- (from SSC) graphs I have been puzzled about the opportunity to do two line marker labels. As I do not see an opportunity to do two line marker labels as value labels are only allowed to have one line, I explored an opportunity to do two line axis labels. Somehow I had the intuition that I was able to do it once.
    So I tried the following code:
    Code:
    sysuse auto, clear
    twoway scatter mpg weight, ///
    name(auto_2linelabel, replace) ///
    xlabel(2000 "Light""weight")
    which fails.

    So I went to Graph Editor and somehow I was able to edit individual labels - even I can change the color of each label.
    Click image for larger version

Name:	scatter-2line-labels.PNG
Views:	1
Size:	19.6 KB
ID:	1688618


    Are there some hidden code options that I need to know to achieve this by code?
    Last edited by Marc Kaulisch; 08 Nov 2022, 06:59.

  • #2
    I don't think you can do two lines of xlabel(), but you can achieve what you need using judicious placement of text(), and telling Stata to not show certain axis labels.

    Consider this, for instance, where I ensure Stata does not use an axis label for 2,000 on the horizontal axis (while still putting a tick there), and put a two line
    text() there instead.

    Code:
    sysuse auto, clear
    #delimit ;
    twoway scatter mpg weight,
        name(auto_2line_label, replace)
        text(7 2000 "Light" "weight", color(sand)) 
        xlabel(3000(1000)5000) xtick(2000(1000)5000)
        text(35 1500 "Test" "Line1", orientation(vertical) color(dkorange))
        yline(35) 
        scheme(s1color)
        ;
    #delimit cr


    This produces:

    Click image for larger version

Name:	Screenshot 2022-11-08 at 7.45.54 PM.png
Views:	1
Size:	662.0 KB
ID:	1688623

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      I don't think you can do two lines of xlabel(), but you can achieve what you need using judicious placement of text(), and telling Stata to not show certain axis labels.
      Consider this, for instance, where I ensure Stata does not use an axis label for 2,000 on the horizontal axis (while still putting a tick there), and put a two line
      text()[FONT=arial] there instead.
      Thank you, I haven't thought about this. Nonetheless, I am quite puzzled that I can achieve individual label editing in Graph Editor`s "edit individual labels" option. The opportunity to achieve this by label-options is more convenient because I do not necessarily know the values of the labels beforehand....

      Comment


      • #4
        You may want to take a look at https://www.statalist.org/forums/for...ariable-labels

        Comment


        • #5
          This is simpler than seems to be feared:

          Code:
          sysuse auto, clear
          twoway scatter mpg weight, ///
          name(auto_2linelabel, replace) ///
          xlabel(2000 `" "Light""weight" "')
          Note that this follows from the rules on quotation marks recently discussed at

          https://www.statalist.org/forums/for...otes-in-locals

          and was in any case discussed here in 2005:

          https://www.stata-journal.com/articl...article=gr0020

          I was a little startled to see a Statalist post of mine from 2019 referred to on Twitter by a member here as an "old" post, so perhaps 2005 qualifies as prehistoric.

          Comment

          Working...
          X