Announcement

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

  • Tabplot: showval percentage format

    Hi all,

    I am trying to change showval option in tabplot, I almost dit it but lamentably I am not able to format label width. Below I attach my result and code example ( I get it from a old post from this forum):

    Code:
    
                   clear
                   input byte(a1 b1 c1)
                   2 1 2
                   1 2 1
                   2 2 2
                   2 2 1
                   2 2 2
                   2 1 1
                   1 2 2
                   3 3 3
                   2 2 2
                   2 2 1
                   1 2 2
                   1 1 1
                   3 3 3
                   3 3 3
                   3 3 3
                   3 3 3
                   1 1 2
                   2 1 1
                   2 1 2
                   3 3 3
                   1 2 2
                   2 2 1
                   1 1 2
                   1 1 1
                   1 2 2
                   2 2 1
                   1 2 2
                   1 2 1
                   1 2 2
                   2 2 1
                   end
                   label values a1 size
                   label values b1 size
                   label values c1 size
                   label def size 1 "big", modify
                   label def size 2 "small", modify
                   label def size 3 "medium", modify
    
                   rename (a1 b1 c1) (size=)
                   gen long id = _n
                   reshape long size, i(id) j(which) string
    
                   bysort which size : gen freq = _N
                   by which : gen pc = 100 * freq / _N
                   gen show = string(freq) + " (" + string(pc, "%2.1f") + "%" +")"
    
    tabplot size, by(which, col(1) compact note("")) ///
    showval(show, offset(0.18)) ///
    subtitle(, pos(9) nobox nobexpand fcolor(none)) ///
    xtitle("") ytitle("") horizontal
    This code output this graph:
    Click image for larger version

Name:	1.png
Views:	2
Size:	12.2 KB
ID:	1540523




    My graph dont show labels properly:
    Click image for larger version

Name:	2.png
Views:	1
Size:	9.6 KB
ID:	1540524




    Please any comment I will grateful.
    Regards
    Rodrigo
    Last edited by Rodrigo Badilla; 09 Mar 2020, 16:55.

  • #2
    Recently I found the answer in a old post from stata list:

    add this option:

    xsc(r(0.8 .))

    Checking the graph below I am thinking in put a line break with the percentage below to frequency, any comments i will grateful.
    Click image for larger version

Name:	3.png
Views:	1
Size:	24.9 KB
ID:	1540528



    Last edited by Rodrigo Badilla; 09 Mar 2020, 17:30.

    Comment


    • #3
      tabplot (from the Stata Journal, as you are asked to explain; FAQ Advice #12) is just a wrapper for graph twoway. What are you doing amounts to adding marker labels inside the command. There isn't code in tabplot to guess whether the axes need to be extended because your marker labels are long and near the edges of the graph. There isn't code in graph twoway to do that either, it seems. So, you need to iterate if you haven't enough space and thus to stretch the axes. As that often arises with direct calls to graph, I don't feel that guilty here.

      Comment


      • #4
        Ok Nick Cox thanks for you reply.

        Comment


        • #5
          In terms of your other question about putting marker labels on two lines, know that I tried various solutions and got nowhere. As with this thread It's hard to tell whether it is graph twoway or the tabplot code that is the problem. I am most reluctant to add yet another option to complicate the command.

          Comment


          • #6
            Thanks Nick Cox , I tried using your article:

            https://www.stata-journal.com/articl...article=gr0020

            But I dont got success...

            Andrew Musau sent me a good approach:

            Code:
            gen show2 = "{sub:"+" (" + string(pc, "%2.1f")+ ")"+"}{sup:"+ string(freq)+ "}"
            
            tabplot size, by(which, col(1) compact note("")) ///
            showval(show2, offset(0.18) mlabsize(large)) ///
            subtitle(, pos(9) nobox nobexpand fcolor(none)) ///
            xtitle("") ytitle("") horizontal

            Comment


            • #7
              Indeed. I saw that and it is a good idea and if you like it, fine. That's a way to get text on two lines, but there will always be an offset. However, you may be able to improve on it in the Graph Editor.

              Comment

              Working...
              X