Announcement

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

  • Printing marker symbols in twoway graph notes

    I'd like to print the filled diamond (D), circle (O), triangle (T) and square (S) symbols in a twoway graph note, ie print elements from symbolstylelist . A legend is not suitable for my purposes here and is in any case being used for a different aspect of the graph.

    I've tried playing around with inserting ASCII codes and reading help graph_text but can't figure out how to do this. Is it possible and if so how can I do this?

  • #2
    I would love to read a better answer, but I fear that it's just not possible except by adding extra material to the graph and dragging it in the Graph Editor to where you wish.

    A better answer might need you to back up and explain what you are trying to do with one or more of data, code and graph. Sometimes people try to do too much and create a complicated design that just may not work well. Many legends can be dispensed with by using direct labelling of some kind.

    Comment


    • #3
      Thanks Nick. I feared it might not be straightforward and that it would be better to reconceptualise the graph. Description & code below and your suggestions are welcome.

      Code:
      twoway ///
          (line unemp_broad year if wc==0, lcolor(red%80) lpat(1)) /// 
          (line unemp_broad year if wc==1, lcolor(blue%80) lpat(1)) ///
          (scatter unemp_broad year if wc==0 & dataset == "PSLSD", mcolor(red%80) msymbol(Sh)) /// 
          (scatter unemp_broad year if wc==0 & dataset == "OHS", mcolor(red%80) msymbol(Th)) /// 
          (scatter unemp_broad year if wc==0 & dataset == "LFS", mcolor(red%80) msymbol(Dh)) /// 
          (scatter unemp_broad year if wc==0 & dataset == "QLFS", mcolor(red%80) msymbol(Oh)) ///    
          (scatter unemp_broad year if wc==1 & dataset == "PSLSD", mcolor(blue%80) msymbol(Sh)) /// 
          (scatter unemp_broad year if wc==1 & dataset == "OHS", mcolor(blue%80) msymbol(Th)) /// 
          (scatter unemp_broad year if wc==1 & dataset == "LFS", mcolor(blue%80) msymbol(Dh)) /// 
          (scatter unemp_broad year if wc==1 & dataset == "QLFS", mcolor(blue%80) msymbol(Oh)) ///
          , ///
          legend(order(1 "South Africa ex. W. Cape" 2 "Western Cape") pos(10) ring(0) region(lstyle(grid) lpattern(1))) ///
          xtitle(Year) xlabel(1992 1994 1996 1998 2000 2002 2004 2006 2008 2010 2012 2014 2016 2018 2020) ///
      I'm plotting unemployment rates for two regions, WC and non-WC from 1993-2019. The graph is aimed at a general audience and what's really important for them is just the distinction between WC and non-WC, which I've put in different colours and is the focus of the legend.
      However a more technical audience will also see the graph, and here the particular datasets used for each estimate are important to indicate. I've done that with marker symbols, but can't figure out how to label them in a way which won't distract the general audience's from the key WC vs non-WC distinction.
      I was thinking I could note the marker symbols and their meaning in a small figure note, hence my question.

      Comment


      • #4
        That helps a lot, but example data would help even more.

        Comment


        • #5
          Sorry, I forgot that I've already collapsed the data so that dataex is easy and feasible. Please find below:

          Anybody using this data should note that it does not represent official statistics and is still a work-in-progress.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input int year str5 dataset float(datayear wc epop_age epop_all unemp_narrow unemp_broad)
          1993 "PSLSD"  1 0   43.2877  25.66949 11.575075  28.25867
          1993 "PSLSD"  1 1  58.95002  40.02303 12.837893 15.341778
          1994 "OHS"    2 0 37.629272  22.59043  21.53025   34.8742
          1994 "OHS"    2 1  57.03881   37.1312 12.594273 17.167778
          1995 "OHS"    3 0  39.44218  23.89657 16.662523 30.472517
          1995 "OHS"    3 1  55.00675 35.616257 12.647474 18.567003
          1996 "OHS"    4 0 35.296604 21.585997  19.90508 34.590275
          1996 "OHS"    4 1  53.92448 35.760418  10.78352 16.435953
          1997 "OHS"    5 0  34.80024  21.38561  21.69876 37.192196
          1997 "OHS"    5 1  52.62454 34.793518 11.525272  16.62779
          1998 "OHS"    6 0  36.46097  22.58968 25.424654  37.71314
          1998 "OHS"    6 1  50.37688 33.378933 13.036005  20.39465
          1999 "OHS"    7 0  38.68893 24.171715 23.412313 36.689865
          1999 "OHS"    7 1  56.79759  37.92036 13.480447  18.56078
          2000 "LFS"    8 0  44.11645 28.045147 25.912853 34.831177
          2000 "LFS"    8 1  57.12346  38.52692 17.370792 21.838173
          2001 "LFS"    9 0  41.27005  26.28032 27.850216  39.12744
          2001 "LFS"    9 1  53.50813  36.21737 18.888426  25.81128
          2002 "LFS"   10 0    39.693 25.415203 30.138435  41.71346
          2002 "LFS"   10 1  53.15442 36.375088   19.2892 25.447405
          2003 "LFS"   11 0  38.40769 24.699163  30.04326  42.74399
          2003 "LFS"   11 1  53.53025   37.1586 20.049875 25.163836
          2004 "LFS"   12 0  38.56971  24.95352  27.34946  41.88274
          2004 "LFS"   12 1  54.51037  38.31557 17.355663  24.18473
          2005 "LFS"   13 0  40.32806  26.43489  26.56784  39.87314
          2005 "LFS"   13 1  54.08863 37.796658 18.073395  24.97023
          2006 "LFS"   14 0  41.21358  27.20921  26.10781  38.84624
          2006 "LFS"   14 1    56.982  40.07972 15.343213  22.79205
          2007 "LFS"   15 0  42.26884  28.00893  24.33847 37.380905
          2007 "LFS"   15 1  56.92589  39.87722  16.16493  22.55709
          2008 "QLFS"  16 0  44.29794  29.49985   22.9093 27.722704
          2008 "QLFS"  16 1  54.86906 36.311554 18.365082 19.652813
          2009 "QLFS"  17 0  42.14711 28.120104  23.87746 30.334726
          2009 "QLFS"  17 1  54.30389 36.077637  20.86405   21.9261
          2010 "QLFS"  18 0  40.27472 26.982843 24.998224  33.27876
          2010 "QLFS"  18 1   52.2564 34.612644  22.17999 23.600586
          2011 "QLFS"  19 0   40.4739 27.109245  24.97868 34.043285
          2011 "QLFS"  19 1  52.52033 34.789204  22.29286  23.35285
          2012 "QLFS"  20 0  40.89496 27.288485 25.069374  34.13872
          2012 "QLFS"  20 1  52.13647 35.616734  23.59755   24.5409
          2013 "QLFS"  21 0  41.60276  27.74965  25.06357   33.9196
          2013 "QLFS"  21 1  52.36125  36.23996  22.64844  23.73588
          2014 "QLFS"  22 0  41.83631 27.884806  25.44421 34.347378
          2014 "QLFS"  22 1  52.57968 36.508446  22.66909 23.513655
          2015 "QLFS"  23 0  42.79813 28.521925 25.995483 34.166916
          2015 "QLFS"  23 1  54.02733  37.33454 20.520655 21.907766
          2016 "QLFS"  24 0  42.16006  28.05906  27.49252  35.49711
          2016 "QLFS"  24 1  53.51059 37.024483  21.13896 22.353313
          2017 "QLFS"  25 0   42.4689 28.248566   28.3017 36.000206
          2017 "QLFS"  25 1  54.72997 37.711487  20.63118  22.23015
          2018 "QLFS"  26 0  42.32203  28.13267  28.05055 36.814632
          2018 "QLFS"  26 1  55.40168  38.19252  19.85144  21.30964
          2019 "QLFS"  27 0  41.54549  27.64176  29.35414  38.05612
          2019 "QLFS"  27 1  54.89125 37.771744 19.606426 21.264635
          end
          label values datayear datayear
          label def datayear 1 "1. PSLSD 1993", modify
          label def datayear 2 "2. OHS 1994", modify
          label def datayear 3 "3. OHS 1995", modify
          label def datayear 4 "4. OHS 1996", modify
          label def datayear 5 "5. OHS 1997", modify
          label def datayear 6 "6. OHS 1998", modify
          label def datayear 7 "7. OHS 1999", modify
          label def datayear 8 "8. LFS 2000", modify
          label def datayear 9 "9. LFS 2001", modify
          label def datayear 10 "10. LFS 2002", modify
          label def datayear 11 "11. LFS 2003", modify
          label def datayear 12 "12. LFS 2004", modify
          label def datayear 13 "13. LFS 2005", modify
          label def datayear 14 "14. LFS 2006", modify
          label def datayear 15 "15. LFS 2007", modify
          label def datayear 16 "16. QLFS 2008", modify
          label def datayear 17 "17. QLFS 2009", modify
          label def datayear 18 "18. QLFS 2010", modify
          label def datayear 19 "19. QLFS 2011", modify
          label def datayear 20 "20. QLFS 2012", modify
          label def datayear 21 "21. QLFS 2013", modify
          label def datayear 22 "22. QLFS 2014", modify
          label def datayear 23 "23. QLFS 2015", modify
          label def datayear 24 "24. QLFS 2016", modify
          label def datayear 25 "25. QLFS 2017", modify
          label def datayear 26 "26. QLFS 2018", modify
          label def datayear 27 "27. QLFS 2019", modify

          Comment


          • #6
            Here's one suggestion that might help depending on how your actual graph looks:
            • create a copy of the variable dataset, perhaps called datasetlab, but then make it empty for all but a select few observations (one observation of year per value of dataset)
            • add the option mlabel(datasetlab) to each individual scatter
            This will put the dataset name on one point of each of your scatterplots, which is likely all you need. By virtue of being on the relevant plot instead of in a note at the bottom, it might also be easier/quicker to comprehend the graph with such labels.

            Edit: just saw #5. I would probably go a different way with this data. Perhaps use the legend to mark the datasets, and use directly positioned text to specify each of the two series?
            Last edited by Hemanshu Kumar; 30 Nov 2022, 06:19.

            Comment


            • #7
              Thanks. Here is a bundle of suggestions on various levels.

              Code:
               line unemp_broad year if wc==0, lcolor(red%80) lpat(1) /// 
                  || line unemp_broad year if wc==1, lcolor(blue%80) lpat(1) ///
                  || scatter unemp_broad year if wc==0 & dataset == "PSLSD", mcolor(red%80) msymbol(Sh) /// 
                  || scatter unemp_broad year if wc==0 & dataset == "OHS", mcolor(red%80) msymbol(Th) /// 
                  || scatter unemp_broad year if wc==0 & dataset == "LFS", mcolor(red%80) msymbol(Dh) /// 
                  || scatter unemp_broad year if wc==0 & dataset == "QLFS", mcolor(red%80) msymbol(Oh) ///    
                  || scatter unemp_broad year if wc==1 & dataset == "PSLSD", mcolor(blue%80) msymbol(Sh) /// 
                  || scatter unemp_broad year if wc==1 & dataset == "OHS", mcolor(blue%80) msymbol(Th) /// 
                  || scatter unemp_broad year if wc==1 & dataset == "LFS", mcolor(blue%80) msymbol(Dh)  /// 
                  || scatter unemp_broad year if wc==1 & dataset == "QLFS", mcolor(blue%80) msymbol(Oh) ///
                  text(39.5 2019 "South Africa ex. W. Cape", color(red) place(w)) ///
                  text(19.5 2019 "Western Cape", color(blue) place(w)) ///
                  text(12 1993.3 "PSLSD", color(gs4) place(w)) ///
                  text(12 1996.5 "OHS", color(gs4))   ///
                  text(12 2003.5 "LFS", color(gs4))  /// 
                  text(12 2013.5 "QLFS", color(gs4)) /// 
                  legend(off) xlabel(1993(2)2019, labsize(small)) xsc(r(1990.5 .)) xtitle("") xli(1993.5 1999.5 2007.5, lw(vthin) lc(gs8)) ytitle(better text here) yla(, ang(h))
              Click image for larger version

Name:	lala.png
Views:	1
Size:	40.7 KB
ID:	1691461

              Comment


              • #8
                Here is one suggestion:

                Code:
                gen serieslab = "South Africa ex. W. Cape" if wc == 0 & year == 2018
                replace serieslab = "Western Cape" if wc == 1 & year == 2016
                separate unemp_broad, by(dataset) veryshortlabel
                
                #delimit ;
                twoway
                    (scatter unemp_broad year if wc==0, lcolor(red%80) lpat(1) ms(i) connect(l) mlabel(serieslab) mlabpos(10) mlabgap(20pt))
                    (scatter unemp_broad year if wc==1, lcolor(blue%80) lpat(1) ms(i) connect(l) mlabel(serieslab) mlabpos(12) mlabgap(20pt))
                    (scatter unemp_broad? year if wc==0, mcolor(red%80 ...) ms(O ...) msize(vsmall ...) )
                    (scatter unemp_broad? year if wc==1, mcolor(blue%80 ...) ms(O ...) msize(vsmall ...))
                    ,
                    text(13 1992.5 "PSLSD", size(vsmall))
                    text(13 1996 "OHS", size(vsmall))
                    text(13 2004 "LFS", size(vsmall))
                    text(13 2014 "QLFS", size(vsmall))
                    xline(1993.5 1999.5 2007.5, lcolor(gs5))
                    legend(off)
                    xtitle(Year) ytitle(Unemployment)
                    xlabel(1992(2)2020)
                    scheme(cleanplots)
                    ;
                #delimit cr
                which produces:
                Click image for larger version

Name:	Screenshot 2022-11-30 at 7.44.04 PM.png
Views:	1
Size:	838.2 KB
ID:	1691471



                Edit: I seem to have come up with something very similar to Nick, which I will pat myself on the back for. The marginal benefit from my contribution is probably just the use of the separate command.
                Last edited by Hemanshu Kumar; 30 Nov 2022, 07:18.

                Comment


                • #9
                  This is really great, thanks Nick Cox! Very much appreciated.

                  I had the same thought as you in your edit after thinking about it a bit, Hemanshu Kumar. Will play around with that compared to Nick's suggestion (which I think looks great). Thanks!

                  Edit: missed your last post Hemanshu, thanks!
                  Last edited by Matthew Lala; 30 Nov 2022, 07:10.

                  Comment


                  • #10
                    I didn't see any of Hemanshu Kumar's posts while I was writing mine. It is enough to know that we came up with the same strategy, often called direct labelling (or labeling, if you use American, not English).

                    A long-time slogan of mine is: Lose the legend! Kill the key! (if you can).

                    Comment


                    • #11
                      The separate command in #8 is a very good idea. My share of the credit is writing it....

                      Comment

                      Working...
                      X