Announcement

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

  • graph matrix with different group colors

    Dear all,
    I was wondering if anyone knows how to do a graph matrix with different colors over different groups;
    For instance, say i want to start with this basic graph:
    Code:
    webuse iris
    graph matrix seplen sepwid petlen petwid, mcolor(gs1%15)
    I would like now to do the same graph, by differentiating the groups by colors. I could do this with different scatter plots:
    Code:
    two scatter seplen sepwid if iris==1, mcolor(red%30) || ///
        scatter seplen sepwid if iris==2, mcolor(blue%30) || ///
        scatter seplen sepwid if iris==3, mcolor(green%30)
    But was wondering if there is any way to do it with "graph matrix"

    Thank you.

  • #2
    I do not believe that you can do this with graph matrix as is. The entire matrix is considered a single graph, so one option applies to all. You could reproduce the matrix by combining several tw scatter graphs using gr combine or by arranging the dataset and using the -by- option in tw scatter.

    Comment


    • #3
      Here's a quick-and-dirty approach using sepscatter from SSC. More work needed e.g. on where a legend should go.


      Code:
      webuse iris, clear 
      
      format pet* sep* %2.0f 
      
      local k = 1 
      local names 
      
      tokenize "seplen sepwid petlen petwid"
      
      forval i = 1/4 {
          local I = `i' + 1 
          forval j = `I'/4  { 
              sepscatter ``i'' ``j'' , sep(iris) name(G`k', replace) legend(off)
              local names   G`k' `names'
              local ++k 
           }
      }
      
      graph combine `names', holes(2 3 6)



      Click image for larger version

Name:	splom.png
Views:	1
Size:	69.4 KB
ID:	1570337

      Comment


      • #4
        Thank you, Andrew and Nick!
        Yes, I tried to go deeper into the syntax behind the graph matrix. I know you can use different markers, and was hoping you could also use different colors.
        In any case, thank you, Nick, I didn't know of that "sepscatter" command. I'll definitely try it out, as I think it will make it easier to construct this kind of graphs
        Fernando

        Comment


        • #5
          See also
          Code:
          ssc install njc_stuff
          for my stuff.

          Comment


          • #6
            For everyone stumbling upon this question: I wrote an ado that does exactly what Fernando asked for. It is now up on the SSC!

            Code:
            ssc install grmatgroups
            webuse iris
            grmatgroups seplen sepwid petlen petwid, over(iris) ///
                markeroptions(1 mcolor(red%30) 2 mcolor(blue%30) 3 mcolor(green%30))

            All best,
            Dominik Flügel

            Comment


            • #7
              Awesome!

              Comment

              Working...
              X