Announcement

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

  • subgroups within graph matrix

    Hello all,
    I'm repeating an old experiment (with new samples), which used a scatter plot matrix to summarized relationships between several characteristics of the samples. The earlier study further binned the samples into 2 categories and displayed them in a single plot using colored markers (blue for category 1, red for category 2). Its straightforward to do this in a regular twoway scatter plot by making if restrictions and using 2 overlaid scatter plots
    Code:
    sysuse auto
    graph twoway (scatter weight mpg if foreign==0) (scatter weight mpg if foreign==1)
    but when I try this with graph matrix I'm informed it is not a twoway type.
    Code:
    graph twoway (matrix weight mpg displacement if foreign==0)(matrix weight mpg displacement if foreign==1)
    Has anyone solved a similar display challenge?

    Thank you for your time
    John Wallace
    Last edited by JohnD Wallace; 05 Jul 2018, 15:47. Reason: Marking up code

  • #2
    Stata is telling you the first problem with your code: matrix is not a twoway type. Fix that and I think you still need a work-around, and here is one:

    Code:
    . sysuse auto, clear 
    (1978 Automobile Data)
    
    . gen mymarker = cond(foreign, "+", "o") 
    
    . graph matrix weight mpg displacement, ms(none) mla(mymarker) mlabpos(0)

    Comment


    • #3
      Thank you very much for the work-around, Nick. This accomplishes the end I'm looking for, nicely.
      -JW

      Comment


      • #4
        If you want to have more flexibility in changing the markers, you can use my ado grmatgroups (available on the SSC):


        Code:
        ssc install grmatgroups
        sysuse auto, clear
        
        grmatgroups weight mpg displacement, over(foreign) ///
        markeroptions(1 msymbol(+) 2 msymbol(Oh))
        All best,
        Dominik Flügel

        Comment

        Working...
        X