Announcement

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

  • twoway : more marker symbol (or special character) ?

    Hello

    I'am trying to write a reusable comand (in Stata 15) to plot a twoway scatter plot (2 continuous vars age and pam_), with groups (dp_ = Present/ Partially present / Absent)

    My problem is that i would like to use 3 marker's symbols (1 style per group)
    -a circle : o (paint in black )
    -a hollow circle : o
    -a hollow circle with a + inside : ⊕

    For the 2 first, all is fine.
    For the hollow circle with a + inside, i can't find a acceptable solution (to be fully reusable without manual editing)

    He is my code :

    Code:
    twoway (scatter pam_ age if sexe=="M" & inclu2==1 & dp_ == "absent",  mcolor(black) msize(medsmall) msymbol(circle_hollow) jitter(1))  ///
     (scatter pam_ age if sexe=="M" & inclu2==1 & dp_ == "partially present",  mcolor(black) msize(medsmall) msymbol(circle_hollow) jitter(1))  ///
     (scatter pam_ age if sexe=="M" & inclu2==1 & dp_ == "partially present",  mcolor(black) msize(medsmall) msymbol("+") jitter(1))  ///
     (scatter pam_ age if sexe=="M" & inclu2==1 & dp_ == "present",  mcolor(black) msize(medsmall) msymbol(circle) jitter(1))  ///
    ,  graphregion(color(white)) yti("PTA (dB)") xti("Age (years)") yla(0(20)90) xla(20(10)80)  ti("M", color(black))  ///
    legend(order (1 "Absent DP" 2 "Partial DP" 3 "Partial DP"  4 "Present DP" ) size(vsmall)  cols(1) ring(0) position(10))  saving(dp_Mbis, replace)
    and the result :
    Click image for larger version

Name:	dp_Mbis.tif
Views:	1
Size:	28.3 KB
ID:	1637948





    The "unacceptable" is the legend that i must edit to superimpose the 2 markers of the "Partial DP" group, like i did in the plot.

    Another way is to manage this group more "properly" = not ploting a o and + superimposed on the scatter plot like i did.

    But then, i'am limited to stata symbols (and characters). There is neither ⊕ in the symbols nor in the char list (0-255).

    And i can't find a way to connect informations about this special caracter ⊕, with Stata
    --unicodeU+2295
    --UTF-8 hex : e2 8a 95
    --numerical HTML encoding : ⊕

    This is probably very simple... I hope someone will be able to help.

    Thank you.
    Last edited by aurelien mulliez; 24 Nov 2021, 08:26.

  • #2
    I am just asking myself why i can't see my subject in the general forum ?
    I'am not sure to have a response if noone see it.

    EDIT : after my reply it seems that the topic is visible
    Last edited by aurelien mulliez; 24 Nov 2021, 10:46.

    Comment


    • #3
      I don't think you can do it directly as these represent two different plots from the perspective of twoway. However, I have seen marginsplot combine symbols, so you may need to talk to the Stata people on how they do this if no one else in the forum knows. Specifying the symbol directly as an addon to the legend works for me. In future, consider providing a reproducible example as I do below (see FAQ Advice #12 for details).

      Code:
      sysuse auto, clear
      tw (scatter mpg weight if !foreign, mcolor(black) msize(medsmall) ///
      msymbol(circle_hollow) jitter(1))(scatter mpg weight if !foreign,  ///
      mcolor(black) msize(medsmall) msymbol(plus) jitter(1) ///
      scheme(s1mono) leg(order(9 "⊕ Domestic"  )))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	28.2 KB
ID:	1637975

      Comment


      • #4
        By the way, using a label in place of a marker is a direct way. But you need to fix the legend as in #3.

        Code:
        sysuse auto, clear
        gen lab="⊕"
        tw (scatter mpg weight if !foreign, mc(none) mlab(lab) mlabpos(0) mlabsize(medsmall) scheme(s1mono))
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.6 KB
ID:	1637982

        Comment


        • #5
          Hi Andrew,

          Thank you for you reply.

          The 2nd proposition, ploting marker with a character is the "prefered" way i think, and i try it but when i copy/paste the ⊕, my editor write a square (unrecognized character).
          But... it works with a variable label created by the command : gen lab="⊕" (the pgm editor shows the unrecognized character square, but the data editor shows the "circle + (⊕)"

          Then, here is the code (that anybody can reproduce)

          Code:
          sysuse auto, clear
          gen lab="⊕" if !foreign
          replace lab="●" if foreign
          
          tw (scatter mpg weight if !foreign, mcolor(black) msize(medsmall) msymbol(circle_hollow) jitter(1)) ///
          (scatter mpg weight if !foreign, mcolor(black) msize(medsmall) msymbol(plus) jitter(1)) ///
          (scatter mpg weight if foreign,  mcolor(black) msize(medsmall) msymbol(circle_hollow) jitter(1)), ///
          scheme(s1mono) leg(order(8 "⊕ Domestic" 9 "○ Foreign"  ))
          the result :


          Click image for larger version

Name:	Graph.png
Views:	1
Size:	69.4 KB
ID:	1638049


          Maybe just a last question : is it possible to change the marker format in the legend (bigger o) neither affecting the scatter nor the text in legend ?

          Last edited by aurelien mulliez; 25 Nov 2021, 02:45.

          Comment


          • #6
            As far as I know, Unicode is supported in Stata versions 14+. You just have to shop for the right symbol at the Unicode store as these come in varying sizes.

            Code:
            sysuse auto, clear
            gen lab="`=ustrunescape("\u2295")'" if !foreign
            tw (scatter mpg weight if !foreign, mc(none) mlab(lab) mlabpos(0) mlabsize(small) scheme(s1mono)) ///
            (scatter mpg weight if foreign, mcolor(black) msize(medsmall) msymbol(circle_hollow) jitter(1) ///
            leg(order(7 "`=ustrunescape("\u2d32")'  Domestic" 8 "`=ustrunescape("\u2d54")'  Foreign")))
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	58.1 KB
ID:	1638068

            Comment


            • #7
              Thank you, it's absolutely answering my needs

              Comment

              Working...
              X