Announcement

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

  • How to include double quotes in labels without breaking lines

    Dear all,

    I am trying to include two labels with double quotes (i.e., "Good" vs. "Poor" and "Great" vs. "Good") on the y-axis of a plot. The double quotes are essential, so I tried using compound double quotes in my code:

    ylabel(1 "Switch-up" ///
    2 "Switch-down" ///
    3 `"Distance to "Good""' ///
    4 `"Distance to "Great""' ///
    5 `""Good" vs. "Poor""' ///
    6 `""Great" vs. "Good""') ///


    However, this code breaks the 5th and 6th labels into three separate lines, and the double quotes are not displayed correctly.

    Can anybody help me fix this issue? Thanks in advance.
    Attached Files

  • #2
    Originally posted by Maoliang Ling View Post
    Can anybody help me fix this issue?
    It might not be especially gratifying—and I hope someone else chimes in with a better fix—but here's something that works in a pinch: I inserted three nonbreaking spaces (ANSI character 160) in the value labels, one before the first double-quotation mark and one each before and after the vs.. Code and image below.
    Code:
    version 18.0
    
    clear *
    
    quietly set obs 6
    generate byte y = _n
    label values y YLabels
    generate double x = y - 1
    
    *
    * Begin here
    *
    label define YLabels 1 "Switch-up" ///
    2 "Switch-down" ///
    3 `"Distance to "Good""' ///
    4 `"Distance to "Great""' ///
    5 `" "Good" vs. "Poor""' /// <= three ANSI 160s here
    6 `" "Great" vs. "Good""' // <= ditto
    
    graph twoway scatter y x, scheme(s2color) msize(vsmall) mcolor(black) ///
        ytitle("") ylabel( , valuelabels angle(horizontal) nogrid) ///
        xtitle("")
    
    exit
    I inserted the characters with the alt key and ten-key pad (I use Windows), but you can use Stata's Unicode features in order to programmatically insert the characters.

    Click image for larger version

Name:	Double-quotation Marks.png
Views:	1
Size:	22.9 KB
ID:	1765657

    Comment


    • #3
      Code:
      label define YLabels 6 `" `""Great" vs. "Good""' "'

      Comment


      • #4
        Dear Joseph and Bjarte,

        Thank you both very much. Your solutions work perfectly. Another method I discovered is to "trick" Stata:

        ylabel(1 "Upgrades" ///
        2 "Downgrades" ///
        3 `"Distance to "Good""' ///
        4 `"Distance to "Great""' ///
        5 `"{sub:}"Good" vs. "Poor""' ///
        6 `"{sub:}"Great" vs. "Good""') ///

        Comment

        Working...
        X