Announcement

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

  • Time series box plots with overlaid connected scatter plot of mean data

    Hello,

    I have some coral rugosity data for 7 locations measured in four years (2008, 2011, 2014, 2017).
    I am hoping to present this as a series of box plots with the mean coral rugosity for each location overlaid as a connected scatter graph.

    I have been successful in doing both parts of this separately, but I would love some helping combining them.

    So far I have used the code // graph box praslinsw praslinne mahee anne mahew mahenw cousin , over(year) // to plot the annual data for the seven locations
    the variables are the 7 locations

    and the code // stripplot praslinsw, over(year) vertical box(bfcolor(gs14) barw(0.2)) ms(none) addplot (scatter mpraslinsw myear, connect(1)) // to create the type of diagram I would like for one location where I plot the mean data on top of the box plot for a single location.

    However, as far as I am aware, I cannot use stripplot for multiple variables.

    Is there a way / code that would enable me to achieve the output of the second code, but, with all 7 locations on one diagram such as in code one?

    I have attached the data in csv format (apologies). Cols A-H are the annual data and cols I-P are the mean data I would like superimposed.

    Many thanks in advance.

    Attached Files

  • #2
    Emi:

    stripplot is from SSC and appears to be my program.

    I think you need a different shape for your data. With some geographical guesses, this shows some technique, including how to give a data example here. I am sure there's a better order than alphabetical for the sites, but I don't know what it is.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(praslinsw praslinne mahee anne mahew mahenw cousin) int year
    1.3813252 1.2643156 1.6433717  1.289185  1.573146  1.279366  1.471054 2008
    1.2688537 1.3983604         . 1.2293084 1.4486754 1.3037505 1.3125348 2008
    1.3268278 1.3156092         . 1.2572062 1.4447026 1.4640462 1.2199537 2008
     1.293173 1.3716743  1.431087 1.4424366 1.6007212   1.39218 1.3653748 2008
    1.3038007 1.3234112         .   1.55322 1.2879527 1.4773988 1.3500224 2008
    1.2995743  1.366183         . 1.4829302 1.5118024  1.369009 1.2868264 2008
      1.28748 1.2975848         . 1.8088055  1.459879 1.5575746  1.281555 2008
    1.4478402 1.3199602         .  1.864506  1.658549 1.6402614 1.2476583 2008
    1.3837314 1.3295943 2.0934074 1.2182485 1.6099123   1.55527 1.2429873 2008
    1.3160696 1.3500608         . 1.3004405 1.9910164  1.444184  1.274332 2008
     1.345906  1.313849         .  1.344488 1.5788195  1.411408  1.260205 2008
    1.2928842 1.2815255  1.507837 1.2396938  1.230283 1.3811854 1.2873765 2008
    1.3025652 1.4094005         . 1.2443882  1.371976   1.48539 1.3165226 2008
    1.3252265 1.2522213         . 1.3411727   1.75474 1.5389413 1.3512477 2008
     1.295601 1.2761213         . 1.3241556 1.7596246 1.5094492  1.311538 2008
     1.310541 1.2791806         . 1.2813675 1.5472937 1.3697386 1.3152938 2008
    1.2958752 1.3148783  1.311854  1.283781  1.512281 1.6295743 1.3158144 2011
     1.291179 1.3236524 1.3417767  1.283939 1.4522895 1.7536724 1.3125348 2011
     1.290471  1.291179  1.335465  1.284805 1.5223664 1.4724754 1.3257194 2011
     1.269562 1.2756745  1.319593 1.2436955  1.596902  1.609492 1.3004405 2011
     1.293607 1.2965834 1.3472716  1.208121  1.607606   1.80871 1.2948782 2011
    1.3124486  1.283781  1.322006  1.240127   1.48838 1.5459048  1.303562 2011
     1.328768 1.2918873 1.5149215  1.314398 1.4909937 1.6214715  1.302306 2011
     1.306553 1.3187983 1.5339828 1.3225044  1.646482   1.63542 1.3246564 2011
            .         .         . 1.8104322         .         .         . 2011
            .         .         . 1.7680765         .         .         . 2011
            .         .         . 1.6902585         .         .         . 2011
            .         .         . 1.4476025         .         .         . 2011
            .         .         . 1.5687468         .         .         . 2011
            .         .         .  1.671214         .         .         . 2011
            .         .         . 1.7690904         .         .         . 2011
            .         .         . 1.6436052         .         .         . 2011
    1.3837768 1.3394527  1.553562  1.448424  1.870787 2.2919006 1.3135318 2014
     1.331059 1.2975804  1.375678 1.6272502 2.0246625 2.3536673 1.3244983 2014
    1.3185166  1.291305 1.6491113 1.3932134  2.384625 2.2962327 1.3013067 2014
     1.280425  1.286483  1.435717 1.3628805 2.0305572 2.0992572 1.3388946 2014
    1.2957717 1.2945895 1.4661608 1.5448375  1.969027  1.736442 1.3165226 2014
    1.4135655 1.2918873 1.3366265 1.3601768 2.0924392  2.264877  1.326781 2014
    1.3222405  1.289474 1.4455094 1.3162045 1.8801028 1.4434466  1.322085 2014
     1.329421 1.2367167 1.3622522  1.338523 2.0622885 1.2963598  1.337459 2014
    1.3225044  1.286483 1.3215348 1.3211936  1.263771 1.1679177         . 2017
     1.306553 1.2776684 1.3437294  1.299942 1.3436422 1.1813552         . 2017
    1.2954557  1.273261 1.3494225  1.306869  1.340116 1.2092508         . 2017
    1.2954557 1.2927536 1.3264923  1.315959 1.3478445  1.242153         . 2017
     1.306553 1.2899218 1.3703586  1.287588  1.296404  1.192182         . 2017
    1.3155257 1.2604605  1.378858  1.270559  1.226524 1.2484946         . 2017
    1.3516657 1.3047976   1.33048 1.2688537 1.1948118 1.3082843         . 2017
    1.3650744  1.312375  1.332632   1.29417 1.2124268 1.3234572         . 2017
    end
    
    rename (praslinsw-cousin) (rugosity=)
    gen id = _n
    reshape long rugosity, i(id) j(site) string
    replace site = proper(site) if inlist(site, "anne", "cousin") 
    replace site = "Mahe E" if site == "mahee" 
    replace site = "Mahe W" if site == "mahew" 
    replace site = "Mahe NW" if site == "mahenw" 
    replace site = "Praslin NE" if site == "praslinne" 
    replace site = "Praslin SW" if site == "praslinsw" 
          
    egen mean = mean(rugosity), by(site year)
    
    stripplot rugosity, over(year) xtitle("") by(site, note("") row(2)) ///
    subtitle(, fcolor(red*0.2))vertical box(bfcolor(gs14) barw(0.2)) ms(none) addplot(connect mean year)

    Click image for larger version

Name:	corals.png
Views:	1
Size:	28.8 KB
ID:	1454044

    Comment


    • #3
      Hi Nick!

      Thanks for this and your help - the output you attach looks wonderful!

      I was hoping to have a look at how the data would look if the all locations were plotted on the same graph. Is there a way to do this? But if this is too messy and crowded, then the above is great!

      Thanks, Emi

      Comment


      • #4
        If this is all the data, it is not clear that the box plots help much. I think you are going to have a spaghetti problem if you superimpose. That is, you will have several tangled lines difficult to distinguish, even with only 7 series.

        With the same reshaping as in #2 -- but with lines like

        Code:
        replace site = "Mah{c e'} E" if site == "mahee"
        to put the accents where they belong -- I tried this with fabplot (SSC). See the thread https://www.statalist.org/forums/for...e-on-ssc/page2 (especially, but not only, #30 there).

        Front-and-back plots can include scatter plots too. That might be a good idea for your raw data.

        Light blue fill colours behind the subtitles are just the default in fabplot. I use set scheme s1color but don't much like the light khaki fill colour that comes as its default.

        Code:
        fabplot connected mean year, by(site, row(2)) xla(2008(3)2017) xsc(r(2007 2018)) xtitle("")  ytitle(mean rugosity) frontopts(lw(medthick)) ms(none)
        Click image for larger version

Name:	corals2.png
Views:	1
Size:	61.9 KB
ID:	1454324

        Comment


        • #5
          Ah, yes I agree about the spaghetti problem! But, these look great -I've made them this morning and it worked a treat, thank you so much!

          Comment

          Working...
          X