Announcement

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

  • BOX PLOT WITH INDIVIDUAL OBSERVATION--How to write

    Hi to everybody. I have to do a boxplot with individual observations using the dataset below:


    clear
    input str3 Litter str6 Strain str3 Strain_old byte Pnd double(Peso Temperatura)
    "1B" "B6_2" "B6" 2 . .
    "2B" "B6_2" "B6" 2 1.1 27.6
    "3B" "B6_2" "B6" 2 1.2 26.8
    "4B" "B6_2" "B6" 2 2.6 29.3
    "5B" "B6_2" "B6" 2 1.3 30.3
    "6B" "B6_2" "B6" 2 1.5 27.7
    "7B" "B6_2" "B6" 2 1.3 29.5
    "8B" "B6_2" "B6" 2 1.3 28.1
    "1B" "B6_4" "B6" 4 1.8 30.5
    "2B" "B6_4" "B6" 4 1.6 29.6
    "3B" "B6_4" "B6" 4 1.6 30.6
    "4B" "B6_4" "B6" 4 1.7 30.4
    "5B" "B6_4" "B6" 4 1.9 31.2
    "6B" "B6_4" "B6" 4 2.3 32.1
    "7B" "B6_4" "B6" 4 2.2 30.8
    "8B" "B6_4" "B6" 4 2 31.8
    "1B" "B6_6" "B6" 6 2.6 31.4
    "2B" "B6_6" "B6" 6 2.2 31.4
    "3B" "B6_6" "B6" 6 2.3 31.5
    "4B" "B6_6" "B6" 6 2.6 30.2
    "5B" "B6_6" "B6" 6 2.6 31.2
    "6B" "B6_6" "B6" 6 3.3 32.5
    "7B" "B6_6" "B6" 6 3.2 31.7
    "8B" "B6_6" "B6" 6 2.9 32.5
    "1B" "B6_8" "B6" 8 3.5 33.1
    "2B" "B6_8" "B6" 8 2.9 31.7
    "3B" "B6_8" "B6" 8 3.2 30.1
    "4B" "B6_8" "B6" 8 3.3 32.7
    "5B" "B6_8" "B6" 8 3.3 33.3
    "6B" "B6_8" "B6" 8 4.5 31.8
    "7B" "B6_8" "B6" 8 4.2 32.9
    "8B" "B6_8" "B6" 8 4 32.4
    "1B" "B6_12" "B6" 12 5.9 33.4
    "2B" "B6_12" "B6" 12 5 32.9
    "3B" "B6_12" "B6" 12 5.3 30.2
    "4B" "B6_12" "B6" 12 4.7 33.5
    "5B" "B6_12" "B6" 12 4.4 33.8
    "6B" "B6_12" "B6" 12 6.7 34.4
    "7B" "B6_12" "B6" 12 6.1 33.8
    "8B" "B6_12" "B6" 12 5.9 34.3
    "1F" "FVB_2" "FVB" 2 1.8 31.8
    "2F" "FVB_2" "FVB" 2 1.6 29.7
    "3F" "FVB_2" "FVB" 2 1.6 30.4
    "4F" "FVB_2" "FVB" 2 1.8 30.3
    "5F" "FVB_2" "FVB" 2 1.8 30.3
    "6F" "FVB_2" "FVB" 2 2 29.7
    "7F" "FVB_2" "FVB" 2 1.5 30.9
    "8F" "FVB_2" "FVB" 2 1.8 30.8
    "9F" "FVB_2" "FVB" 2 1.8 30.5
    "10F" "FVB_2" "FVB" 2 2.6 31.1
    "1F" "FVB_4" "FVB" 4 2.6 31
    "2F" "FVB_4" "FVB" 4 2.4 31.5
    "3F" "FVB_4" "FVB" 4 2.1 31.3
    "4F" "FVB_4" "FVB" 4 2.8 30.9
    "5F" "FVB_4" "FVB" 4 2.6 31.1
    "6F" "FVB_4" "FVB" 4 2.9 31.7
    "7F" "FVB_4" "FVB" 4 2.2 30.8
    "8F" "FVB_4" "FVB" 4 2.7 31.6
    "9F" "FVB_4" "FVB" 4 2.6 30.8
    "10F" "FVB_4" "FVB" 4 3.6 31.3
    "1F" "FVB_6" "FVB" 6 3.6 31.7
    "2F" "FVB_6" "FVB" 6 3.4 32.1
    "3F" "FVB_6" "FVB" 6 2.7 30.8
    "4F" "FVB_6" "FVB" 6 3.8 32.5
    "5F" "FVB_6" "FVB" 6 3.5 31.4
    "6F" "FVB_6" "FVB" 6 4 32.6
    "7F" "FVB_6" "FVB" 6 3.1 32.3
    "8F" "FVB_6" "FVB" 6 3.5 32.8
    "9F" "FVB_6" "FVB" 6 3.6 32.2
    "10F" "FVB_6" "FVB" 6 4.6 33.6
    "1F" "FVB_8" "FVB" 8 4.3 33.4
    "2F" "FVB_8" "FVB" 8 4.5 33.4
    "3F" "FVB_8" "FVB" 8 3 30.8
    "4F" "FVB_8" "FVB" 8 5 32.2
    "5F" "FVB_8" "FVB" 8 4.2 32.1
    "6F" "FVB_8" "FVB" 8 4.8 33.1
    "7F" "FVB_8" "FVB" 8 4 32
    "8F" "FVB_8" "FVB" 8 4.3 32.9
    "9F" "FVB_8" "FVB" 8 4.5 33.5
    "10F" "FVB_8" "FVB" 8 5.6 33.8
    "1F" "FVB_12" "FVB" 12 5.7 33.9
    "2F" "FVB_12" "FVB" 12 6.1 34
    "3F" "FVB_12" "FVB" 12 3.5 31.5
    "4F" "FVB_12" "FVB" 12 6.2 34.1
    "5F" "FVB_12" "FVB" 12 6.1 33.4
    "6F" "FVB_12" "FVB" 12 6.4 34.6
    "7F" "FVB_12" "FVB" 12 5.2 33.7
    "8F" "FVB_12" "FVB" 12 5.8 34.3
    "9F" "FVB_12" "FVB" 12 6 34.6
    "10F" "FVB_12" "FVB" 12 7.1 34.4
    "1C" "CD1_2" "CD1" 2 2 30.7
    "2C" "CD1_2" "CD1" 2 1.6 30.2
    "3C" "CD1_2" "CD1" 2 1.8 30.9
    "4C" "CD1_2" "CD1" 2 2 29.3
    "5C" "CD1_2" "CD1" 2 1.8 28.7
    "6C" "CD1_2" "CD1" 2 2.2 29.9
    "7C" "CD1_2" "CD1" 2 2.6 30.2
    "8C" "CD1_2" "CD1" 2 1.7 30.2
    "9C" "CD1_2" "CD1" 2 2.1 31.1
    "10C" "CD1_2" "CD1" 2 2.7 30.7
    end
    [/CODE]
    ------------------ copy up to and including the previous line ------------------

    I WROTE this code:

    sort Strain
    by Strain: egen med = median(Peso)
    by Strain: egen lqt = pctile(Peso), p(25)
    by Strain: egen uqt = pctile(Peso), p(75)


    label def Strain 1 "B6_2" 2 "B6_4" 3 "B6_6" 4 "B6_8" 5 "B6_12" 8 "FVB_2" 9 "FVB_4" 10 "FVB_6" 11 "FVB_8" 12 "FVB_12" 15 "CD1_2" 16 "CD1_4" 17 "CD1_6" 18 "CD1_8" 19 "CD1_12"
    encode Strain, gen(axis) label(Strain)


    local colours grey grey grey grey grey blue blue blue blue blue green green green green green
    local Colours grey grey grey grey grey blue blue blue blue blue green green green green green

    local values 1 2 3 4 5 8 9 10 11 12 15 16 17 18 19


    set scheme s1color

    forval j = 1/15 {
    local c : word `j' of `colours'
    local C : word `j' of `Colours'
    local v : word `j' of `values'

    local call `call' || rbar lqt med axis if axis == `v', barw(0.6) fcolor(`c') lcolor(`C') ///
    || rbar uqt med axis if axis == `v', barw(0.6) fcolor(`c') lcolor(`C') ///
    || scatter Peso axis if axis == `v', mc(`C') ms(Oh)
    }

    twoway `call' xla(1 2 3 4 5 8 9 10 11 12 15 16 17 18 19, noticks valuelabel labsize(small)) legend(off) ytitle(Peso) xtitle("") yla(, ang(h)) xli(4 8, lw(vthin) lc(gs12))



    I ATTACHED WHAT I'VE GOT (prova17052021.ppt) , but i think that's a misstake

    1)How to write more clearly the x-axis legend

    1 "B6_2" 2 "B6_4" 3 "B6_6" 4 "B6_8" 5 "B6_12" 8 "FVB_2" 9 "FVB_4" 10 "FVB_6" 11 "FVB_8" 12 "FVB_12" 15 "CD1_2" 16 "CD1_4" 17 "CD1_6" 18 "CD1_8" 19 "CD1_12"?


    2) HOW TO ADD THE LINE TO SEPARATE THE THREE GROUPS (B6, FVB, CD1) THANKS TO EVERYBODY

    Thanks to everybody

    Attached Files

  • #2
    This may help. I used stripplot from SSC and labmask from the Stata Journal.

    Code:
    clear
    input str3 Litter str6 Strain str3 Strain_old byte Pnd double(Peso Temperatura)
    "1B" "B6_2" "B6" 2 . .
    "2B" "B6_2" "B6" 2 1.1 27.6
    "3B" "B6_2" "B6" 2 1.2 26.8
    "4B" "B6_2" "B6" 2 2.6 29.3
    "5B" "B6_2" "B6" 2 1.3 30.3
    "6B" "B6_2" "B6" 2 1.5 27.7
    "7B" "B6_2" "B6" 2 1.3 29.5
    "8B" "B6_2" "B6" 2 1.3 28.1
    "1B" "B6_4" "B6" 4 1.8 30.5
    "2B" "B6_4" "B6" 4 1.6 29.6
    "3B" "B6_4" "B6" 4 1.6 30.6
    "4B" "B6_4" "B6" 4 1.7 30.4
    "5B" "B6_4" "B6" 4 1.9 31.2
    "6B" "B6_4" "B6" 4 2.3 32.1
    "7B" "B6_4" "B6" 4 2.2 30.8
    "8B" "B6_4" "B6" 4 2 31.8
    "1B" "B6_6" "B6" 6 2.6 31.4
    "2B" "B6_6" "B6" 6 2.2 31.4
    "3B" "B6_6" "B6" 6 2.3 31.5
    "4B" "B6_6" "B6" 6 2.6 30.2
    "5B" "B6_6" "B6" 6 2.6 31.2
    "6B" "B6_6" "B6" 6 3.3 32.5
    "7B" "B6_6" "B6" 6 3.2 31.7
    "8B" "B6_6" "B6" 6 2.9 32.5
    "1B" "B6_8" "B6" 8 3.5 33.1
    "2B" "B6_8" "B6" 8 2.9 31.7
    "3B" "B6_8" "B6" 8 3.2 30.1
    "4B" "B6_8" "B6" 8 3.3 32.7
    "5B" "B6_8" "B6" 8 3.3 33.3
    "6B" "B6_8" "B6" 8 4.5 31.8
    "7B" "B6_8" "B6" 8 4.2 32.9
    "8B" "B6_8" "B6" 8 4 32.4
    "1B" "B6_12" "B6" 12 5.9 33.4
    "2B" "B6_12" "B6" 12 5 32.9
    "3B" "B6_12" "B6" 12 5.3 30.2
    "4B" "B6_12" "B6" 12 4.7 33.5
    "5B" "B6_12" "B6" 12 4.4 33.8
    "6B" "B6_12" "B6" 12 6.7 34.4
    "7B" "B6_12" "B6" 12 6.1 33.8
    "8B" "B6_12" "B6" 12 5.9 34.3
    "1F" "FVB_2" "FVB" 2 1.8 31.8
    "2F" "FVB_2" "FVB" 2 1.6 29.7
    "3F" "FVB_2" "FVB" 2 1.6 30.4
    "4F" "FVB_2" "FVB" 2 1.8 30.3
    "5F" "FVB_2" "FVB" 2 1.8 30.3
    "6F" "FVB_2" "FVB" 2 2 29.7
    "7F" "FVB_2" "FVB" 2 1.5 30.9
    "8F" "FVB_2" "FVB" 2 1.8 30.8
    "9F" "FVB_2" "FVB" 2 1.8 30.5
    "10F" "FVB_2" "FVB" 2 2.6 31.1
    "1F" "FVB_4" "FVB" 4 2.6 31
    "2F" "FVB_4" "FVB" 4 2.4 31.5
    "3F" "FVB_4" "FVB" 4 2.1 31.3
    "4F" "FVB_4" "FVB" 4 2.8 30.9
    "5F" "FVB_4" "FVB" 4 2.6 31.1
    "6F" "FVB_4" "FVB" 4 2.9 31.7
    "7F" "FVB_4" "FVB" 4 2.2 30.8
    "8F" "FVB_4" "FVB" 4 2.7 31.6
    "9F" "FVB_4" "FVB" 4 2.6 30.8
    "10F" "FVB_4" "FVB" 4 3.6 31.3
    "1F" "FVB_6" "FVB" 6 3.6 31.7
    "2F" "FVB_6" "FVB" 6 3.4 32.1
    "3F" "FVB_6" "FVB" 6 2.7 30.8
    "4F" "FVB_6" "FVB" 6 3.8 32.5
    "5F" "FVB_6" "FVB" 6 3.5 31.4
    "6F" "FVB_6" "FVB" 6 4 32.6
    "7F" "FVB_6" "FVB" 6 3.1 32.3
    "8F" "FVB_6" "FVB" 6 3.5 32.8
    "9F" "FVB_6" "FVB" 6 3.6 32.2
    "10F" "FVB_6" "FVB" 6 4.6 33.6
    "1F" "FVB_8" "FVB" 8 4.3 33.4
    "2F" "FVB_8" "FVB" 8 4.5 33.4
    "3F" "FVB_8" "FVB" 8 3 30.8
    "4F" "FVB_8" "FVB" 8 5 32.2
    "5F" "FVB_8" "FVB" 8 4.2 32.1
    "6F" "FVB_8" "FVB" 8 4.8 33.1
    "7F" "FVB_8" "FVB" 8 4 32
    "8F" "FVB_8" "FVB" 8 4.3 32.9
    "9F" "FVB_8" "FVB" 8 4.5 33.5
    "10F" "FVB_8" "FVB" 8 5.6 33.8
    "1F" "FVB_12" "FVB" 12 5.7 33.9
    "2F" "FVB_12" "FVB" 12 6.1 34
    "3F" "FVB_12" "FVB" 12 3.5 31.5
    "4F" "FVB_12" "FVB" 12 6.2 34.1
    "5F" "FVB_12" "FVB" 12 6.1 33.4
    "6F" "FVB_12" "FVB" 12 6.4 34.6
    "7F" "FVB_12" "FVB" 12 5.2 33.7
    "8F" "FVB_12" "FVB" 12 5.8 34.3
    "9F" "FVB_12" "FVB" 12 6 34.6
    "10F" "FVB_12" "FVB" 12 7.1 34.4
    "1C" "CD1_2" "CD1" 2 2 30.7
    "2C" "CD1_2" "CD1" 2 1.6 30.2
    "3C" "CD1_2" "CD1" 2 1.8 30.9
    "4C" "CD1_2" "CD1" 2 2 29.3
    "5C" "CD1_2" "CD1" 2 1.8 28.7
    "6C" "CD1_2" "CD1" 2 2.2 29.9
    "7C" "CD1_2" "CD1" 2 2.6 30.2
    "8C" "CD1_2" "CD1" 2 1.7 30.2
    "9C" "CD1_2" "CD1" 2 2.1 31.1
    "10C" "CD1_2" "CD1" 2 2.7 30.7
    end
    
    gen label = substr(Strain, strpos(Strain, "_") + 1, .) 
    
    gen axis = sum(Strain != Strain[_n-1]) + sum(Strain_old != Strain_old[_n-1]) - 1 
    
    labmask axis, values(label)
    
    set scheme s1color
    
    stripplot Peso, over(axis) box centre vertical xtitle("") xmla(3 "B6" 9 "FVB" 15 "CD1", tlength(*7) tlc(none) labsize(medlarge)) yla(, ang(h)) separate(Strain_old) ms(Oh ..) mcolor(grey green blue) legend(off) xsc(r(. 17)) xli(6 12, lc(gs8) lw(thin))
    Click image for larger version

Name:	peso.png
Views:	1
Size:	33.7 KB
ID:	1610018

    Comment


    • #3
      thanks a lot..
      .i cannot perform this with stata 12 isn't it? I think with stata 16


      and if I wanted the colored boxes too???

      thanks a million

      Comment


      • #4
        stripplot is written for Stata 8.2. labmask is written for Stata 7. Different colours for boxes aren't supported currently in stripplot.

        Comment


        • #5
          thank you.very much..@Nick Cox.I AM A new user of STATA


          If I understand correctly it is impossible to do, for example grey box for "B6", Blue box for "FVB" and green for "CD1" isn' it?
          is there any way to overcome this?

          and to represent First the time point 2 foreach group (B6 2 FVB 2 CD1 2) , then the timepoint 4 for each group (B6 4, FBV 4, CD1 4..)..and so on...I could i do??? (I ATTACHED THE HISTOGRAM I DID (in practice i ve to obtain individual boxplot )

          thanks a million

          Tommaso






          Attached Files

          Comment


          • #6
            It's not impossible. Just not supported with stripplot at present. If different colours are important to you, I suggest going back to your original code.

            Please note the request to show graphs as
            .png. The explanation at FAQ Advice #12 about attachments using MS Word and MS Excel surely carries over to other MS Office applications.

            Comment


            • #7
              Yes I THINK to return to my original code, but surely i made a mistake because the legend of x-axis in not clear (as using stripplot) and also i ve to show first time "2" for B6, FVB, CD1- time 4 for B6, FVB and CD1. and so on.and i don't know how to do.

              Can you help me Nick Cox ?

              Thank you so much!!!

              Comment


              • #8
                I'll try bu i cannot able to find the error..
                I ATTACH AGAIN THE GRAPH...

                Thank you Nick Cox
                Attached Files

                Comment


                • #9
                  I don't understand #8 which seems to be about something else.

                  It seems to me that you just need to mix some of my code with some of yours. stripplot was only clearer about axis labels because of prior work to separate out prefix and suffix. It seems to me that you don't have enough space to repeat the prefixes readably. Also, this code blanks out the fill colour for the boxes, which I suggest interferes too much with the display of marker symbols.

                  In your case, you have the complete dataset and so xla(1/5 7/11 13/17, noticks valuelabel) should work.

                  Code:
                  clear
                  input str3 Litter str6 Strain str3 Strain_old byte Pnd double(Peso Temperatura)
                  "1B" "B6_2" "B6" 2 . .
                  "2B" "B6_2" "B6" 2 1.1 27.6
                  "3B" "B6_2" "B6" 2 1.2 26.8
                  "4B" "B6_2" "B6" 2 2.6 29.3
                  "5B" "B6_2" "B6" 2 1.3 30.3
                  "6B" "B6_2" "B6" 2 1.5 27.7
                  "7B" "B6_2" "B6" 2 1.3 29.5
                  "8B" "B6_2" "B6" 2 1.3 28.1
                  "1B" "B6_4" "B6" 4 1.8 30.5
                  "2B" "B6_4" "B6" 4 1.6 29.6
                  "3B" "B6_4" "B6" 4 1.6 30.6
                  "4B" "B6_4" "B6" 4 1.7 30.4
                  "5B" "B6_4" "B6" 4 1.9 31.2
                  "6B" "B6_4" "B6" 4 2.3 32.1
                  "7B" "B6_4" "B6" 4 2.2 30.8
                  "8B" "B6_4" "B6" 4 2 31.8
                  "1B" "B6_6" "B6" 6 2.6 31.4
                  "2B" "B6_6" "B6" 6 2.2 31.4
                  "3B" "B6_6" "B6" 6 2.3 31.5
                  "4B" "B6_6" "B6" 6 2.6 30.2
                  "5B" "B6_6" "B6" 6 2.6 31.2
                  "6B" "B6_6" "B6" 6 3.3 32.5
                  "7B" "B6_6" "B6" 6 3.2 31.7
                  "8B" "B6_6" "B6" 6 2.9 32.5
                  "1B" "B6_8" "B6" 8 3.5 33.1
                  "2B" "B6_8" "B6" 8 2.9 31.7
                  "3B" "B6_8" "B6" 8 3.2 30.1
                  "4B" "B6_8" "B6" 8 3.3 32.7
                  "5B" "B6_8" "B6" 8 3.3 33.3
                  "6B" "B6_8" "B6" 8 4.5 31.8
                  "7B" "B6_8" "B6" 8 4.2 32.9
                  "8B" "B6_8" "B6" 8 4 32.4
                  "1B" "B6_12" "B6" 12 5.9 33.4
                  "2B" "B6_12" "B6" 12 5 32.9
                  "3B" "B6_12" "B6" 12 5.3 30.2
                  "4B" "B6_12" "B6" 12 4.7 33.5
                  "5B" "B6_12" "B6" 12 4.4 33.8
                  "6B" "B6_12" "B6" 12 6.7 34.4
                  "7B" "B6_12" "B6" 12 6.1 33.8
                  "8B" "B6_12" "B6" 12 5.9 34.3
                  "1F" "FVB_2" "FVB" 2 1.8 31.8
                  "2F" "FVB_2" "FVB" 2 1.6 29.7
                  "3F" "FVB_2" "FVB" 2 1.6 30.4
                  "4F" "FVB_2" "FVB" 2 1.8 30.3
                  "5F" "FVB_2" "FVB" 2 1.8 30.3
                  "6F" "FVB_2" "FVB" 2 2 29.7
                  "7F" "FVB_2" "FVB" 2 1.5 30.9
                  "8F" "FVB_2" "FVB" 2 1.8 30.8
                  "9F" "FVB_2" "FVB" 2 1.8 30.5
                  "10F" "FVB_2" "FVB" 2 2.6 31.1
                  "1F" "FVB_4" "FVB" 4 2.6 31
                  "2F" "FVB_4" "FVB" 4 2.4 31.5
                  "3F" "FVB_4" "FVB" 4 2.1 31.3
                  "4F" "FVB_4" "FVB" 4 2.8 30.9
                  "5F" "FVB_4" "FVB" 4 2.6 31.1
                  "6F" "FVB_4" "FVB" 4 2.9 31.7
                  "7F" "FVB_4" "FVB" 4 2.2 30.8
                  "8F" "FVB_4" "FVB" 4 2.7 31.6
                  "9F" "FVB_4" "FVB" 4 2.6 30.8
                  "10F" "FVB_4" "FVB" 4 3.6 31.3
                  "1F" "FVB_6" "FVB" 6 3.6 31.7
                  "2F" "FVB_6" "FVB" 6 3.4 32.1
                  "3F" "FVB_6" "FVB" 6 2.7 30.8
                  "4F" "FVB_6" "FVB" 6 3.8 32.5
                  "5F" "FVB_6" "FVB" 6 3.5 31.4
                  "6F" "FVB_6" "FVB" 6 4 32.6
                  "7F" "FVB_6" "FVB" 6 3.1 32.3
                  "8F" "FVB_6" "FVB" 6 3.5 32.8
                  "9F" "FVB_6" "FVB" 6 3.6 32.2
                  "10F" "FVB_6" "FVB" 6 4.6 33.6
                  "1F" "FVB_8" "FVB" 8 4.3 33.4
                  "2F" "FVB_8" "FVB" 8 4.5 33.4
                  "3F" "FVB_8" "FVB" 8 3 30.8
                  "4F" "FVB_8" "FVB" 8 5 32.2
                  "5F" "FVB_8" "FVB" 8 4.2 32.1
                  "6F" "FVB_8" "FVB" 8 4.8 33.1
                  "7F" "FVB_8" "FVB" 8 4 32
                  "8F" "FVB_8" "FVB" 8 4.3 32.9
                  "9F" "FVB_8" "FVB" 8 4.5 33.5
                  "10F" "FVB_8" "FVB" 8 5.6 33.8
                  "1F" "FVB_12" "FVB" 12 5.7 33.9
                  "2F" "FVB_12" "FVB" 12 6.1 34
                  "3F" "FVB_12" "FVB" 12 3.5 31.5
                  "4F" "FVB_12" "FVB" 12 6.2 34.1
                  "5F" "FVB_12" "FVB" 12 6.1 33.4
                  "6F" "FVB_12" "FVB" 12 6.4 34.6
                  "7F" "FVB_12" "FVB" 12 5.2 33.7
                  "8F" "FVB_12" "FVB" 12 5.8 34.3
                  "9F" "FVB_12" "FVB" 12 6 34.6
                  "10F" "FVB_12" "FVB" 12 7.1 34.4
                  "1C" "CD1_2" "CD1" 2 2 30.7
                  "2C" "CD1_2" "CD1" 2 1.6 30.2
                  "3C" "CD1_2" "CD1" 2 1.8 30.9
                  "4C" "CD1_2" "CD1" 2 2 29.3
                  "5C" "CD1_2" "CD1" 2 1.8 28.7
                  "6C" "CD1_2" "CD1" 2 2.2 29.9
                  "7C" "CD1_2" "CD1" 2 2.6 30.2
                  "8C" "CD1_2" "CD1" 2 1.7 30.2
                  "9C" "CD1_2" "CD1" 2 2.1 31.1
                  "10C" "CD1_2" "CD1" 2 2.7 30.7
                  end
                  
                  gen label = substr(Strain, strpos(Strain, "_") + 1, .) 
                  
                  gen axis = sum(Strain != Strain[_n-1]) + sum(Strain_old != Strain_old[_n-1]) - 1 
                  
                  labmask axis, values(label)
                  
                  set scheme s1color
                  
                  bysort Strain: egen med = median(Peso)
                  by Strain: egen lqt = pctile(Peso), p(25)
                  by Strain: egen uqt = pctile(Peso), p(75)
                  
                  local colours grey blue green 
                  
                  foreach value in B6 FVB CD1  {
                      gettoken colour colours : colours 
                      local call `call' || rbar lqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') ///
                      || rbar uqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') ///
                      || scatter Peso axis if Strain_old == "`value'", mc(`colour') ms(Oh)
                  }
                  
                  twoway `call' xla(1/5 7/11 13, noticks valuelabel) legend(off) ytitle(Peso) xtitle("") yla(, ang(h)) xli(6 12, lw(vthin) lc(gs12)) /// 
                  xmla(3 "B6" 9 "FVB" 15 "CD1", tlength(*7) tlc(none) labsize(medlarge)) yla(, ang(h)) xsc(r(. 17))

                  Click image for larger version

Name:	peso2.png
Views:	1
Size:	33.0 KB
ID:	1610068

                  Comment


                  • #10
                    Thanks a million,



                    However, this code group by types of mice (B6, FVB, CD1). IF I WANTED TO GROUP FOR TIMEPOINT (2, 4 ,6 ,8 ,12)?
                    In practice I should get a figure like the one I attach but using "stripplot"
                    Is it more clear?
                    Thanks a million Nick Cox


                    Attached Files

                    Comment


                    • #11
                      Nick Cox , I ll disturb you for another thing:

                      when i run the code below:

                      twoway `call' xla(1/5 7/11 13/17, noticks valuelabel) legend(off) ytitle(Peso) xtitle("") yla(, ang(h)) xli(6 12, lw(vthin) lc(gs12))///
                      xmla(3 "B6" 9 "FVB" 15 "CD1", tlength(*7) tlc(none) labsize(medlarge)) yla(, ang(h)) xsc(r(. 17))




                      Stata gives the error I dont know why.

                      r(100);
                      ) required

                      Comment


                      • #12
                        Nick Cox
                        was I clear in exporting the problem? I don't know where to turn my head

                        thanks a lot!!!

                        Comment


                        • #13
                          #11 I can't see the problem there.

                          #10 This sounds like the same problem with different order.

                          Note that Stata recognises "gray" but not "grey" as a colour.


                          Code:
                          label def order 1 B6 2 FVB 3 CD1 
                          encode Strain_old, gen(order) label(order) 
                          sort Pnd order 
                          gen axis = sum(Pnd != Pnd[_n-1]) + sum(order != order[_n-1]) - 1 
                          
                          labmask axis, values(Strain_old)
                          
                          set scheme s1color
                          
                          bysort Strain: egen med = median(Peso)
                          by Strain: egen lqt = pctile(Peso), p(25)
                          by Strain: egen uqt = pctile(Peso), p(75)
                          
                          local colours gray blue green  
                          
                          foreach value in B6 FVB CD1 {
                              gettoken colour colours : colours 
                              local call `call' || rbar lqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') ///
                              || rbar uqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') ///
                              || scatter Peso axis if Strain_old == "`value'", mc(`colour') ms(Oh)
                          }
                          
                          twoway `call' xla(1/3 5/7 9/11 13/15 17/19, labsize(small) noticks valuelabel) legend(off) ytitle(Peso) xtitle("") yla(, ang(h)) xli(4(4)16, lw(vthin) lc(gs12)) /// 
                          xmla(2 "2" 6 "4" 10 "6" 14 "8" 18 "12", tlength(*7) tlc(none) labsize(medlarge)) yla(, ang(h))

                          Comment


                          • #14
                            Good morning Nick Cox I 've just run the code you suggest me, but always the same error


                            label def order 1 B6 2 FVB 3 CD1 encode Strain_old, gen(order) label(order) sort Pnd order gen axis = sum(Pnd != Pnd[_n-1]) + sum(order != order[_n-1]) - 1 labmask axis, values(Strain_old) set scheme s1color bysort Strain: egen med = median(Peso) by Strain: egen lqt = pctile(Peso), p(25) by Strain: egen uqt = pctile(Peso), p(75) local colours gray blue green foreach value in B6 FVB CD1 { gettoken colour colours : colours local call `call' || rbar lqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') /// || rbar uqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') /// || scatter Peso axis if Strain_old == "`value'", mc(`colour') ms(Oh) } twoway `call' xla(1/3 5/7 9/11 13/15 17/19, labsize(small) noticks valuelabel) legend(off) ytitle(Peso) xtitle("") yla(, ang(h)) xli(4(4)16, lw(vthin) lc(gs12)) /// xmla(2 "2" 6 "4" 10 "6" 14 "8" 18 "12", tlength(*7) tlc(none) labsize(medlarge)) yla(, ang(h)) /************************************************** *********************/ label def order 1 B6 2 FVB 3 CD1 . encode Strain_old, gen(order) label(order) . sort Pnd order . gen axis = sum(Pnd != Pnd[_n-1]) + sum(order != order[_n-1]) - 1 . end of do-file . do "C:\Users\SALVIT~1\AppData\Local\Temp\STD3c3c_0000 00.tmp" . labmask axis, values(Strain_old) . set scheme s1color . . bysort Strain: egen med = median(Peso) . by Strain: egen lqt = pctile(Peso), p(25) . by Strain: egen uqt = pctile(Peso), p(75) . . local colours gray blue green . . foreach value in B6 FVB CD1 { 2. gettoken colour colours : colours 3. local call `call' || rbar lqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') /// > || rbar uqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') /// > || scatter Peso axis if Strain_old == "`value'", mc(`colour') ms(Oh) 4. } . end of do-file . do "C:\Users\SALVIT~1\AppData\Local\Temp\STD3c3c_0000 00.tmp" . twoway `call' xla(1/3 5/7 9/11 13/15 17/19, labsize(small) noticks valuelabel) legend(off) ytitle(Peso) xtitle("") yla(, ang(h)) xli(4(4)16, lw(vthin) lc(gs12)) /// > xmla(2 "2" 6 "4" 10 "6" 14 "8" 18 "12", tlength(*7) tlc(none) labsize(medlarge)) yla(, ang(h)) ) required r(100); end of do-file r(100); Where is the mistake? Please help me Tommaso

                            Comment


                            • #15
                              Good morning Nick Cox I 've just run the code you suggest me, but always the same error

                              label def order 1 B6 2 FVB 3 CD1 encode Strain_old, gen(order) label(order) sort Pnd order gen axis = sum(Pnd != Pnd[_n-1]) + sum(order != order[_n-1]) - 1 labmask axis, values(Strain_old) set scheme s1color bysort Strain: egen med = median(Peso) by Strain: egen lqt = pctile(Peso), p(25) by Strain: egen uqt = pctile(Peso), p(75) local colours gray blue green foreach value in B6 FVB CD1 { gettoken colour colours : colours local call `call' || rbar lqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') /// || rbar uqt med axis if Strain_old == "`value'", barw(0.6) fcolor(none) lcolor(`colour') /// || scatter Peso axis if Strain_old == "`value'", mc(`colour') ms(Oh) } twoway `call' xla(1/3 5/7 9/11 13/15 17/19, labsize(small) noticks valuelabel) legend(off) ytitle(Peso) xtitle("") yla(, ang(h)) xli(4(4)16, lw(vthin) lc(gs12)) /// xmla(2 "2" 6 "4" 10 "6" 14 "8" 18 "12", tlength(*7) tlc(none) labsize(medlarge)) yla(, ang(h))
                              ) required
                              r(100);

                              end of do-file

                              r(100);

                              ALWAYS THE SAME ERROR " )required




                              Comment

                              Working...
                              X