Announcement

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

  • graph catplot note overlaps with xaxis

    While creating some graphs I have discovered that a three line note overlaps with xaxis-title and (in some cases goes into the barregion). I use -catplot- (from ssc, v 2.0.2) for this example. The problem arises when I use the legend position 3 or 4. I wonder whether it is possible to avoid such overlaps without changing the legend position. In avoiding this problem I switched to -tabplot- (from ssc) which seems to be recommended anyway...

    Click image for larger version

Name:	x_catp_ulb_sf_s2.png
Views:	1
Size:	110.7 KB
ID:	1581378



    The code used:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(ul_bench_u smfield _freq)
    0  1  1
    0  2  9
    0  3  9
    0  5  4
    0  6 60
    0  7  1
    0  8  1
    0  9  2
    0 10  4
    0 11  1
    0 13  4
    0 16 13
    0 17  3
    0 19  3
    1  1  3
    1  2  4
    1  3  9
    1  4  1
    1  5 12
    1  6 45
    1  9  1
    1 10 22
    1 11  8
    1 13  9
    1 14  1
    1 16 19
    1 17  2
    2  5  4
    2 10  1
    2 11  2
    2 16  9
    2 17  1
    2 19  1
    3  1  4
    3  2 10
    3  3  4
    3  5  7
    3  6 20
    3  8  2
    3 10  1
    3 11  1
    3 14  1
    3 16  8
    3 17  2
    4  1  1
    4  2  9
    4  3  8
    4  5 15
    4  6 23
    4  7  1
    4  8  2
    4  9  2
    4 10  7
    4 11  5
    4 12  2
    4 13  1
    4 16 24
    4 17  4
    5  2  7
    5  3 10
    5  5  8
    5  6 54
    5  9  2
    5 10  2
    5 13  1
    5 15  1
    5 16 10
    5 17  1
    5 19  1
    6  2  1
    6  3  4
    6  5 14
    6  6 70
    6  7  2
    6  8  5
    6  9  2
    6 10  1
    6 13  2
    6 14  1
    6 16 27
    6 17  4
    6 19  1
    7  1  1
    7  2 16
    7  3 12
    7  5 18
    7  6 40
    7  8  1
    7 11  7
    7 13  4
    7 16 15
    7 17  7
    7 19  1
    end
    label values ul_bench_u l_ul_bench_u
    label def l_ul_bench_u 0 "Uni A", modify
    label def l_ul_bench_u 1 "Uni B", modify
    label def l_ul_bench_u 2 "Uni C", modify
    label def l_ul_bench_u 3 "Uni D", modify
    label def l_ul_bench_u 4 "Uni E", modify
    label def l_ul_bench_u 5 "Uni F", modify
    label def l_ul_bench_u 6 "Uni G", modify
    label def l_ul_bench_u 7 "Uni H", modify
    label values smfield l_smfield
    label def l_smfield 1 "Agriculture, Fisheries & Forestry", modify
    label def l_smfield 2 "Biology", modify
    label def l_smfield 3 "Biomedical Research", modify
    label def l_smfield 4 "Built Environment & Design", modify
    label def l_smfield 5 "Chemistry", modify
    label def l_smfield 6 "Clinical Medicine", modify
    label def l_smfield 7 "Communication & Textual Studies", modify
    label def l_smfield 8 "Earth & Environmental Sciences", modify
    label def l_smfield 9 "Economics & Business", modify
    label def l_smfield 10 "Enabling & Strategic Technologies", modify
    label def l_smfield 11 "Engineering", modify
    label def l_smfield 12 "Historical Studies", modify
    label def l_smfield 13 "Information & Communication Technologies", modify
    label def l_smfield 14 "Mathematics & Statistics", modify
    label def l_smfield 15 "Philosophy & Theology", modify
    label def l_smfield 16 "Physics & Astronomy", modify
    label def l_smfield 17 "Psychology & Cognitive Sciences", modify
    label def l_smfield 19 "Social Sciences", modify
    label var ul_bench_u "Selected universities"
    label var smfield "Feldzuordnung"
    label var _freq "Frequency"
    
    
    catplot smfield [aw=_freq] , stack percent(ul_bench_u) over(ul_bench_u,  label(labs(small))) outergap(1.1) ///
                    name(catp_ulb_sf_s2, replace) asy ///
                    scheme(s2color)     ///
                    legend(stack size(small) col(1) pos(4) region(lstyle(none)) keygap(.5) symy(.6)) ///
                    ytitle("Prozent") l1title("") ///
                    blabel(bar, pos(center) format(%8.0fc) size(tiny)) ///
                    note("{stSerif:Quelle: Eigene Berechnungen nach}" "{stSerif:Ioannidis, John P. A.; Boyack, Kevin W.; Baas, Jeroen (2020): Updated science-wide author databases of standardized citation indicators.}" "{stSerif:In: PLoS biology 18 (10), e3000918. DOI: 10.1371/journal.pbio.3000918.}", span)





  • #2
    This is just graph hbar biting. catplot isn't adding extra code to imply this.

    The option


    Code:
    ysc(titlegap(*12)) 
    improves this detail, but the graph still doesn't work very well. Alphabetical order is not usually a good idea. Howard Wainer parodied this in various places as "Alabama first!" or "Austria first!". I suppose a German equivalent might be "Aach first!".

    Giving a reference is always fine, but does it have to be on the same slide, even in a presentation?

    Comment


    • #3
      Thank you very much. Yeah, in the original the subject fields are strings so I simply encoded it. I'll think about a more systematic approach. Like humanities first and so on...

      But another question related to -tabplot- (ssc) irrespective of the note:
      Code:
      tabplot smfield ul_bench_u [aw=_freq] , percent(ul_bench_u) showval(,mlabs(vsmall) mlabg(tiny)) separate(smfield) xtitle("") ytitle("") subtitle("") ///
                  xlabel(,alternate) scheme(s2color) ///
                  name(tabp_ulb_sf_s2, replace)
      I get the message that
      (note: named style p16bar not found in class seriesstyle, default attributes used)
      (note: named style p17bar not found in class seriesstyle, default attributes used)
      (note: named style p18bar not found in class seriesstyle, default attributes used)

      Now I have added various p16-p18 controls to my scheme (like color p16, seriessytle p17bar p17bar etc.)
      But nonetheless the colors of categories 16-18 are the same as p1 (as given in the code as I seee like pstyle(p1bar) ).
      Do you have a hint for me how I can change in my scheme to control colors of p16...?


      Comment


      • #4
        tabplot is please to be cited as coming from the Stata Journal.

        It isn't interfering with your scheme choices, which are up to you, so far as I can see.

        Comment


        • #5
          Dear Nick Cox , I've discovered that we had the issue where to cite -tabplot- from already last year... After contacting Stata Tech Support I learned that the scheme is not expandable beyond p15 - so any p16, p17 or p18... attributes in a scheme are ignored. So I thought I have to add something to -tabplot-. I tweaked it the following way - you may be able to do it much more elegant.

          Add after rows 265:
          Code:
                   if inrange(`J',1,15) {
                    local pstb  = `J'
                    }
                    if inrange(`J',16,30) {
                    local pstb  = `J' - 15
                    }
          I've changed the two sections for the -separate- option into:
          Code:
                    if "`separate'" != "" { 
                        if `Jm1' <= 15 {
                        forval j = 1/`Jm1' { 
                            local barcall `barcall' || rbar ``j'' `col' `row' if `tag',       ///
                            horizontal `one' `notwithby' `recast' `bw' `yscale' `xscale'      ///
                                            pstyle(p`j'bar) `barall' `bar`j''  
                        } 
                        }
                        else if inrange(`Jm1',16,30) == 1 { 
                        forval j = 1/15 { 
                            local barcall `barcall' || rbar ``j'' `row' `col' if `tag',  ///
                            `one' `notwithby' `recast' `yscale' `xscale' `bw'            ///
                            pstyle(p`j'bar) `barall' `bar`j''
                        }   
                        forval j = 16/`Jm1' { 
                        local b16 = `j' - 15 
                            local barcall `barcall' || rbar ``j'' `row' `col' if `tag',  ///
                            `one' `notwithby' `recast' `yscale' `xscale' `bw'            ///
                            pstyle(p`b16'bar) `barall' `bar`j''
                        }
                        }
                          local barcall `barcall' || rbar ``J'' `col' `row' if `tag',  ///
                        horizontal xti("`xtitle'")                                   ///
                        xla(`xlevels', val grid angle(-.001) labgap(2) `noxti')      ///
                        `one' `notwithby' `recast' yti("`ytitle'") `bw'              ///
                        `yscale' `xscale' `by' pstyle(p`pstb'bar) `barall' `bar`J''
          I do not get any message about missing styles and the graph looks okay and see:

          Click image for larger version

Name:	x_tabp_mk.png
Views:	1
Size:	76.4 KB
ID:	1582593

          Comment


          • #6
            Thanks very much for the suggestion. In essence you managed to hack tabplot for a work-around you want and that's fine by me. I have more reservations about folding this back into the distributed code for which I am responsible and which I have to document.

            To put it very bluntly, I don't want to allow users to do something that's not to me obviously a good idea. Nor do I want to explain this as I don't really understand the logic and insofar as I as understand it the argument is unconvincing.

            Correct me if I am wrong: but it seems that you are using 15 colours for more than 15 categories, so that some colours mean one thing but the other colours may mean different things. Tastes can vary but I don't want that to happen in my graphs. Good use of colour can make graphs attractive and it can make them easier to read, but the arbitrary limit chosen by StataCorp -- although as said arbitrary -- seems to me a good choice.

            On a different level: for graphs like yours with many bars mostly showing small quantities (zero or positive) I have used square root scale for bar height but shown the percents as they are. It has worked well for me, but might be a complication too far for your circumstances. I regularly encounter puzzlement about log scales even, which seemed clear enough to us early in secondary school but seem to provoke reactions from puzzlement to hostility, even among some highly educated audiences. A square root scale may well seem too bizarre to be worthwhile, but it's what I would try if your data were mine.

            Comment


            • #7
              Nick, of course you are absolutly right and thank you for your patience.
              I was driven by the puzzle of getting a note on missing styles where I should have rather looked at what I want to say and to highlight. In this sense the highlighting should not go into the subject categories but into the university categories.

              Regarding the scales I have to see. At the moment I am satisified with the result and the learning by error.

              Comment


              • #8
                I agree. Different colours for the universities would add some zest and not complicate interpretation.

                Comment

                Working...
                X