Announcement

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

  • How to mamage the size of the legend key marker independently of scatterpolt msize() option

    Dear experts,
    I am trying to make a scatterplot consisting of 4 groups of dots which make 4 lines. I would like to keep these "lines" as thin as possible so in the scatter definition I indicated the option msize(vtiny). You can see the plot as a first attachment, ds_by_dy.jpg.
    The negative side is that in the legend key Stata also plots marker as it is defined in the scatter command, in my situation - very tiny, which is almost impossible to see in the legend. I am sure I can do this using graph editor:
    start graph editor -> go to legend dropdown list on the right side of the screen -> click legend -> click key region -> right click key[whichever you need] -> in the key properties window select Size: medium (see attachment #2, lc_ear2).
    The question is: how to do this in code? Again: I want only the legend keys to be changed, the ones on the scatterplot must remain very tiny.
    Sincerely,
    Mik
    Attached Files

  • #2
    Well, you can 'deceive' Stata using the following code (suppose you using stcolor scheme, or else you must modify mcolor option). The original method is here: Re: st: key symbol size in legend https://www.stata.com/statalist/arch.../msg00253.html

    Code:
    set obs 1000
    gen xvar=runiform()
    gen bq1=chi2den(5,x)
    gen bq2=chi2den(7,x)
    gen bq3=chi2den(9,x)
    twoway scatter bq1 bq2 bq3 xvar, msize(vtiny vtiny vtiny) || scatter bq1 bq2 bq3 xvar if xvar==., mcolor(stc1 stc2 stc3) legend(order(4 5 6))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	194.7 KB
ID:	1774983

    Last edited by Chen Samulsion; 28 Mar 2025, 05:52. Reason: add: set obs 1000

    Comment


    • #3
      Great idea, thank you! It worked fine.
      Mik

      Comment

      Working...
      X