Announcement

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

  • Dotplot with multiple variables

    Hello,

    I am trying to create a way to display a data index I have created for coral rugosity (data attached).
    The Stata dot plot graph is the best way I have found to present this data using the code: graph dot index, over(genus, sort((mean) index)) to give the attached result after a little editing.

    However, each coral is also part of a morphotype group (branching, columnar etc.) that I would like to be distinguished. Is there a way I can add the data separately for each morphotype, with the data for each colour coded?
    Click image for larger version

Name:	2019-08-18 (6).png
Views:	1
Size:	146.9 KB
ID:	1512739


    Many thanks,
    Emi
    Attached Files

  • #2
    Emi: Various problems here, some quite soluble.

    1. You're asked to post using dataex, as below. See FAQ Advice #12.

    2. Screenshots are less visible than .png See FAQ Advice #12.

    3. As I read it only the first 66 observations in your data file should be included. The rest are summaries, included with the data, spreadsheet-style.

    4. When I import the data I see trailing spaces in some cases, which should be trimmed. Stata is minded to regard "frog" and "frog " as different categories. It's not human enough to ignore the trailing spaces.

    5. When genus is really species, the specific name should be lower case. It's Homo sapiens or Urtica dioica, not Homo Sapiens, etc.

    6. I am not sure that you are being consistent in using parentheses, but that's cosmetic.

    7. When you were a student with me [full disclosure!], the Stata you were using always had a default of scheme s1color, because that is how it was installed on the University network. I recommend avoiding s2color, which is evidently now your default on a different network.

    Now to the important stuff. I count 16 morphotypes; that being so, you would need 16 different colours and a legend explaining them will take up a large fraction of your available space. That isn't going to work well at all. The graph is already too crowded.

    You can introduce a different grouping to avoid that. Morphotype need not in alphabetical order, so I work out group means and create a new ordering variable. For what is below you need to install labmask from the Stata Journal.

    If I recall correctly rugosity cannot be less than 1 any way.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str29 genus str19 morphotype float index
    "Acropora Branching"            "Acropora"            3.24
    "Acropora (stubby branches)"    "Acropora"            2.07
    "Acropora (flat plate)"         "Acropora"            2.08
    "Acropora (outwards branching)" "Acropora"            1.58
    "Acropora Corymbrose"           "Acropora"            2.18
    "Acropora Digitate"             "Acropora"            2.75
    "Acropora Hispidose"            "Acropora"            2.06
    "Porites Compressa"             "Porites"             2.25
    "Porites Cyclindrica"           "Porites"             3.08
    "Porites lobata"                "Porites"             1.93
    "Porites unknown"               "Porites"             1.83
    "Porites rus "                  "Porites"              2.4
    "Acanthastrea"                  "Encrusting"          1.23
    "Fungia"                        "Free-living"         1.57
    "Galaxea"                       "Encrusting"          2.81
    "Astreopora"                    "Encrusting"          1.46
    "Sandolithia "                  "Free-living"         1.33
    "Herpolitha"                    "Free-living"         1.76
    "Pavona"                        "Encrusting"           1.9
    "Astreopora"                    "Massive"             1.57
    "Coscinaraea"                   "Submassive "         1.95
    "Acanthastrea"                  "Massive"             1.84
    "Galaxea"                       "Massive"             2.63
    "Favites"                       "Massive"             1.83
    "Leptoria"                      "Massive"             1.81
    "Coscinaraea"                   "Encrusting"          1.28
    "Favia"                         "Massive"             1.33
    "Goniastrea"                    "Massive"             1.76
    "Coscinaraea"                   "Massive"             1.85
    "Platgyra"                      "Massive"             2.08
    "Diploria "                     "Massive"             1.75
    "Leptoria"                      "Submassive"          1.39
    "Leptastrea"                    "Encrusting"          2.06
    "Oulophyllia"                   "Massive"             1.92
    "Leptastrea"                    "Submassive"             2
    "Pachyseris"                    "Plates and tables"   1.94
    "Montipora"                     "Plates and tables"   1.51
    "Leptastrea"                    "Massive"             1.85
    "Merulina "                     "Mixed"               1.77
    "Heliopora"                     "Fossil branching"    2.16
    "Diploastrea"                   "Massive"             3.84
    "Goniopora"                     "Massive"             2.57
    "Mussa"                         "Flabello-meandroid " 2.11
    "Lobophyllia"                   "Flabello-meandroid " 3.82
    "Symphyllia"                    "Flabello-meandroid " 2.11
    "Turbinaria (vase)"             "Contorted laminar"   1.98
    "Turbinaris single plate"       "Plates and tables"   1.79
    "Pocillopora (stubby branches)" "Branching"           1.37
    "Pectina "                      "Foliose"             2.92
    "Seriatopora "                  "Branching"           2.61
    "Psammocora"                    "Foliose"             2.33
    "Isopora"                       "Branching"           1.63
    "Trachyphyllia"                 "Flabello-meandroid " 2.38
    "Pavona Clavus "                "Columnar"            3.72
    "Echinopora "                   "Branching"           2.49
    "Stylophora"                    "Branching"           1.46
    "Montipora"                     "Branching"           2.49
    "Pavona cactus"                 "Foliose"             2.67
    "Alveopora"                     "Columnar"            2.23
    "Pocillopora (big branches)"    "Flattened branching" 2.55
    "Turbinaria contorted "         "Contorted laminar"   2.35
    "Montipora Vase"                "Contorted laminar"   3.63
    "Merulina vase"                 "Contorted laminar"   2.34
    "Sinularia"                     "Soft"                1.47
    "Lobophytum - Sacrophyton"      "Soft"                1.53
    "Lobophytum"                    "Soft"                2.14
    "Branching"                     "Morphotype"          2.48
    "Acropora Plates and Tables"    "Morphotype"          1.94
    "Columnar"                      "Morphotype"          2.68
    "Contorted laminar"             "Morphotype"           3.5
    "Encrusting"                    "Morphotype"          1.62
    "Flabello-meandroid "           "Morphotype"          2.02
    "Free-living"                   "Morphotype"          1.39
    "Foliose"                       "Morphotype"          2.61
    "Massive"                       "Morphotype"          1.78
    "Mixed contorted "              "Morphotype"          2.18
    "Micro-atoll"                   "Morphotype"          2.09
    "Plates and tables"             "Morphotype"             2
    "Submassive "                   "Morphotype"          1.84
    "Soft coral "                   "Morphotype"          1.63
    "Digitate and Corymbrose"       "Morphotype"          2.32
    "Big branching"                 "Algae"               2.77
    "All other"                     "Algae"               2.04
    "Coral rubble"                  "Rubble"              1.16
    "Rubble 1:1 Sand"               "Rubble"              1.29
    "Rubble 3:1 Sand"               "Rubble"              1.31
    "Limestone Pavement"            "Rubble"              1.39
    "Low ripple (flat)"             "Sand"                1.02
    "Bioturbated (small)"           "Sand"                1.07
    "Bioturbated (large)"           "Sand"                1.12
    end
    
    replace genus = trim(genus)
    replace genus = upper(substr(genus, 1, 1)) + lower(substr(genus, 2, .)) 
    replace morphotype = trim(morphotype)
    
    egen mean = mean(index), by(morphotype) 
    egen order = group(mean morphotype) 
    labmask order, values(morphotype) 
    
    graph dot (mean) index in 1/66, over(genus, sort(1) label(labsize(tiny))) over(order, ///
    label(labsize(small))) nofill scheme(s1color) marker(1, msize(vsmall) ms(Oh)) exclude0 linetype(line) lines(lc(gs12) lw(vthin)) ///
    aspect(2.5)

    You can mess around with aspect xsize ysize options. Printed big, the graph might not seem too bad.


    Click image for larger version

Name:	emi.png
Views:	1
Size:	48.0 KB
ID:	1512786

    Comment


    • #3
      Hi Nick,

      Many thanks for your reply and help. Apologies for this tardy reply.

      1+2. points from FAQs duly noted

      4. Re. Spelling and spaces etc. also noted

      7 . Is there a way to overwrite s2color and use s1color if best?

      You are correct in that rugosity cannot be below 1.

      Re. The output - that is brilliant, exactly what I was trying to achieve - thank you so much for the time and assistance with this query. It is very much appreciated and has helped me solve a month long problem about how to present this index.

      Best wishes,

      Emi

      Comment


      • #4
        I used scheme(s1color) as an option and you can also go

        Code:
        set scheme s1color
        to set it as default.

        Comment


        • #5
          Thanks Nick.

          Something I have just noticed is that the CCRI values for the morphotypes are not actually summaries (the mean) of the genus data within the each morphotype category. They have been calculated using the same methodology as for the genus categories and contain some additional data too. Is there a way that I can plot the values for the morphotype categories in a different colour on this dot plot in line with the morphotype labels on the left-hand side of the genus labels? Hope this makes sense?

          Thanks,
          Emi

          Comment


          • #6
            In principle, no problem. Just use separate to split your variable in two first. The trick is written up at https://www.stata-journal.com/articl...article=gr0049

            Comment


            • #7
              Hi Nick,

              Great - thank you! After data separation the code below gives the attached result. I have figured out how to specify the marker styles of the two dot categories. How can I ensure that the grey reference lines run through both dot categories too? Thanks, Emi
              Click image for larger version

Name:	GraphDot.1.png
Views:	1
Size:	95.6 KB
ID:	1520390

              ​​​

              graph dot (mean) index1 index0, over(genus, sort(1) label(labsize(tiny))) over(order, label(labsize(small))) nofill scheme(s1color) marker(1, msize(vsmall) ms(Oh)) marker(2, msize(vsmall) ms(Oh)) exclude0 linetype(line) lines(lc(gs12) lw(vthin)) aspect(2.5)
              Last edited by Emi Husband; 14 Oct 2019, 13:49.

              Comment


              • #8
                I don't know why those lines don't appear. I have to say that I don't think the graph is improved by squeezing yet more detail in. It looks pretty much unreadable. My guess is that if you wave it at some colleagues, they will gently tell you so. You'd be better off with one graph for detail and one for summary.

                Comment


                • #9
                  Hello,

                  Just a quick follow up question to the ones from above - despite them being a little while ago now.

                  Is there a way to add error bars to dot plots? I know you can use rcap for two-way plots, but I am not sure if such code is transferrable to this type of chart?

                  Thanks and best wishes,
                  Emi

                  Comment


                  • #10
                    WIth graph dot the most you can do to use say pipe symbols as in this example:


                    Code:
                    
                    
                    clear
                    set obs 5
                    gen whatever = _n
                    gen upper = w + 0.5 
                    gen lower = w - 0.5 
                    gen id = _n
                    graph dot (asis) lower whatever upper , over(id) ///
                    marker(1, ms(|) msize(*2) mc(black)) marker(2, ms(O)) marker(3, ms(|) msize(*2) mc(black)) ///
                    scheme(s1color) linetype(line) lines(lc(gs12) lw(thin)) legend(off)
                    Orthodox error bars require
                    graph twoway.

                    Comment


                    • #11
                      Apologies for the delay in acknowledging your response Nick. This was the perfect solution - thank you very much for this, and for introducing me to dotplot, a very useful graph.

                      Comment

                      Working...
                      X