Announcement

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

  • Size graph more height but same width

    Dear all,

    I am struggling in creating a graph that fits my needs.
    I need to have a graph that is longer than the default size, and I know that this can be done by using the ysize(#) option.

    However if I do that the graph rescales all the text in a way that I cannot control properly and create issues to both my legend and my title.

    Here is an example you can easely replicate with the auto dataset. With default size both titles and legends fits well, but if I use the ysize(#) option, everything get messed up:

    Code:
    use "http://www.stata-press.com/data/r13/auto", clear
    
    scatter mpg trunk headroom turn gear_ratio weight, title("This is a very long long long long long long long title", span) legend( label(1 "this is a long long long text") label(2 "this is a long long long long text")) 
    
    scatter mpg trunk headroom turn gear_ratio weight, title("This is a very long long long long long long long title", span) legend( label(1 "this is a long long long text") label(2 "this is a long long long long text")) ysize(10)
    Can you suggest me a way to have a longer graph but that keep fixed the size of the text ?

    Any help would be great.
    Best.
    D.

  • #2
    You cannot fit what you cannot fit. Either use a smaller font size or split the title (legend) into multiple lines (rows).

    Code:
    sysuse auto, clear
    scatter mpg trunk headroom turn gear_ratio weight, ///
    title("This is a very long long long" "long long long long title", span) ///
    legend( label(1 "this is a long long long text") ///
    label(2 "this is a long long long long text") col(1)) ysize(10)

    Comment


    • #3
      Hi Andrew,
      thank you for your reply.

      Actually my issue derives from the fact that everything fits perfectly in the standard dimension, but if I increase the y dimension making the graph ''longer'' , it seams that also the x dimension change, as well as the scale of the text.

      What I would like to have is a graph like the standard but with a longer height.
      in that way everything should fit nicely.

      Do you have any tips on how to achieve something similar?

      Comment


      • #4
        What you seem to want is to increase both the left- and right-hand side margins. See

        Code:
        help legend_options
        for manipulating the legend in a similar manner.

        Code:
        sysuse auto, clear
        scatter mpg trunk headroom turn gear_ratio weight, ///
        title("This is a very long long long long long long long title", span) ///
        legend(off)  graphregion(margin( l=40 r=40))
        Res.:

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.0 KB
ID:	1589497

        Comment


        • #5
          Thank you for your patience Andrew,

          But this is not quite what I am looking for. I would like to have a graph that has the same width of the default but that is longer. However, as you can see from the example, if I just increase the ysize, all the graph changes his look with titles and legends with different size.

          I would like them, and the rest of the graph, to look exactly as the default but more spread along the y-dimension. So it should be as in the default but "longer"

          I hope you can help me out with this.
          Best,
          D

          Comment


          • #6
            Options include ysize() xsize() aspect().

            Comment


            • #7
              Hi Nick,

              Thank you for your message.
              But as I understand it the option aspect only modifies the plot-region and not the whole graph, so I don't think it is useful in this context. Maybe probably I am missing something?

              But I feel that I still did not explain correctly what I need. I will try with an example with picture:

              This is what I have in standard graph:
              Click image for larger version

Name:	Cattura.PNG
Views:	1
Size:	42.4 KB
ID:	1589721


              This is what I would like to have :

              Click image for larger version

Name:	Cattura2.jpg
Views:	1
Size:	95.0 KB
ID:	1589722


              But this is what I get with option ysize(8):

              Click image for larger version

Name:	ysize8.png
Views:	1
Size:	35.4 KB
ID:	1589723


              Comment


              • #8
                Sorry, but I don't have more suggestions beyond http://www.catb.org/~esr/jargon/html...hat-then-.html

                Comment


                • #9
                  Note that your issue is documented under -help aspect option-

                  Specifying an aspect ratio larger than the default for a graph causes the
                  width of the plot region to become narrower. Conversely, specifying a
                  small aspect ratio causes the plot region to become shorter. Because
                  titles and legends can be wider than the plot region, and because most
                  schemes do not allow titles and legends to span beyond the width of the
                  plot region, this can sometimes lead to surprising spacing of some graph
                  elements

                  However, I return to what I said in #2 that you cannot fit what you cannot fit. My suggestion was to reduce the font sizes for the title and the legend. Now, I think this is where there is a misunderstanding. Doing so does not mean that the font size in the default graph will be rendered larger than the one in the modified graph. Once you export the graph (e.g., in .png or .pdf) format, you will find that the exported graphs respect your specified aspect ratio. What you should not do is to make this comparison looking at the graph window. The default aspect ratio corresponds to ysize(4) and xsize(5.5). If you specify ysize(10), the y dimension will be slightly under twice the width of the x dimension. Compare the images in the 2 PDFs produced in the following example where I resize the title- and legend- text sizes. In the rendered graphs, there are about no differences in the text sizes, but the desired aspect ratio is achieved.


                  Code:
                  sysuse auto, clear
                  *DEFAULT
                  scatter mpg trunk headroom turn gear_ratio weight, ///
                  title("This is a very long long long long long long long title") ///
                  legend( label(1 "this is a long long long text") ///
                  label(2 "this is a long long long long text"))
                  graph export "Graph.pdf", as(pdf)  replace
                  *MODIFIED
                  scatter mpg trunk headroom turn gear_ratio weight, ///
                  title("This is a very long long long long long long long title", ///
                  size(14pt)) legend( label(1 "this is a long long long text") ///
                  label(2 "this is a long long long long text") size(11pt)) ysize(10) xsize(5.5)
                  graph export "Graph2.pdf", as(pdf) replace

                  Comment


                  • #10
                    AH Yes, that was the misunderstanding indeed. So I had to specify the size text in the modified graph to achieve the same look of the default one.

                    I think that this is quite counter-intuitive, if I change the ysize I expect all the rest should look the same. But I guess it is what it is.

                    Thank you both verymuch for your patience and your comments.

                    Best
                    D.

                    Comment


                    • #11
                      If you take your very first post above and do the following:
                      Code:
                      sysuse auto, clear
                      
                      scatter mpg trunk headroom turn gear_ratio weight, ///
                      title("This is a very long long long long long" "long long title", span) ///
                      legend(  label(1 "this is a long" "long long text") ///
                      label(2 "this is a long long long long text")) ysize(10)

                      Comment

                      Working...
                      X