Announcement

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

  • Fit graph to window on y-axis

    Dear Stata Experts,

    I have a following code, which produces graphs that are being saved in .tif format. However on y-axis the graphs sometimes are too wide.
    Does anyone have an idea, why?

    Code:
    capture noisily twoway ///
                    (scatter MM_TP TP [aw = total_SalesRevenue_EUR_per_Year] if groups_TP == `i' & PricingCategory_short == "`v'" & TP <= `m_max', title("`Identifier_graph' `v'", color(maroon)) ytitle(Material Margin (%)) mcolor(navy) msymbol(circle_hollow) leg(off)) ///
                    (scatter MM_TP TP if groups_TP_TP == `i' & total_SalesRevenue_EUR_per_Year == 0 & PricingCategory_short == "`v'" & TP <= `m_max', msize(tiny) mcolor(navy) msymbol(circle)) ///
                    (${function_`v'}, range (`m_1_`v'' `m_2_`v'') lpattern(dash) lcolor(white)) || (${function_`v'_1}, range (`m_min' `m_1_`v'') lpattern(dash) lcolor(white)) || (${function_`v'_2}, range (`m_2_`v'' `m_max') lpattern(dash) lcolor(white)) ///
                    (${function_`a'}, range (`m_1_`a'' `m_2_`a'') lcolor(maroon)) || (${function_`a'_1}, range (`m_min' `m_1_`a'') lcolor(maroon)) || (${function_`a'_2}, range (`m_2_`a'' `m_max') lcolor(maroon)) ///
                    (${function_`b'}, range (`m_1_`b'' `m_2_`b'') lcolor(maroon)) || (${function_`b'_1}, range (`m_min' `m_1_`b'') lcolor(maroon)) || (${function_`b'_2}, range (`m_2_`b'' `m_max') lcolor(maroon))
                    
            
                    graph export "${directory}/Output Data/Main regression graphs/MM/`g'/`v'/g_`Identifier_graph'.tif", replace
    The lines are some global macros (${function_`...'} in form y = ....
    Click image for larger version

Name:	Unbenannt10.PNG
Views:	1
Size:	11.5 KB
ID:	1699667



    Some output is more convenient, but still a lot of useless space being shown.
    Click image for larger version

Name:	Unbenannt11.PNG
Views:	1
Size:	12.8 KB
ID:	1699668



    I understand that one can define y-axis range, but still why are the graphs by default so wide (starting from 40 to 100, instead of around 70 to 100)?

    Thank you for any support in this topic.

    Sincerely,

    Pavlo
    Last edited by Paul Shlapa; 31 Jan 2023, 09:37.

  • #2
    Sometimes a graph is drawn to respect the ranges of variables even if the extreme observations concerned are not shown on the graph. Your code is not fully explicit about all your choices, but I can't see that you are explicitly setting the y axis range or labels, which is why you should be puzzled. A way to experiment is temporarily to drop all observations not needed for the graph.

    Comment


    • #3
      Well i have also tried to manually define y-axis range an fit the graph into it (from 0 to 100), but that did not work either.

      Code:
      capture noisily twoway ///
              (scatter MM_$main_regressor TP [aw = total_SalesRevenue_EUR_per_Year] if groups_${main_regressor}_${main_regressor} == `i', title("`Identifier_graph'", color(maroon)) ytitle(Material Margin (%)) mcolor(navy) msymbol(circle_hollow)) ///
              (scatter MM_$main_regressor TP if groups_${main_regressor}_${main_regressor} == `i' & total_SalesRevenue_EUR_per_Year == 0, msize(tiny) mcolor(navy) msymbol(circle)) ///
              (scatter MM_TP TP [aw = total_SalesRevenue_EUR_per_Year] if groups_${main_regressor}_${main_regressor} == `i', mcolor(red) msymbol(X)) ///
              (scatter MM_TP TP if groups_${main_regressor}_${main_regressor} == `i', msize(tiny) mcolor(red) msymbol(circle)) ///
              (${function_`a'}, range (`m_1_`a'' `m_2_`a'') lcolor(maroon)) || (${function_`a'_1}, range (`m_min' `m_1_`a'') lcolor(maroon)) || (${function_`a'_2}, range (`m_2_`a'' `m_max') lcolor(maroon)) ///
              (${function_`b'}, range (`m_1_`b'' `m_2_`b'') lcolor(maroon)) || (${function_`b'_1}, range (`m_min' `m_1_`b'') lcolor(maroon)) || (${function_`b'_2}, range (`m_2_`b'' `m_max') lcolor(maroon)) ///
              (${function_`v'}, range (`m_1_`v'' `m_2_`v'') lpattern(dash) lcolor(white)) || (${function_`v'_1}, range (`m_min' `m_1_`v'') lpattern(dash) lcolor(white)) || (${function_`v'_2}, range (`m_2_`v'' `m_max') lpattern(dash) lcolor(white)), ///
              yscale(range(0 100)) legend(off)
      yrange also does not work.

      Unbenannt1.PNG

      Without the Lines everything works.

      Code:
      capture noisily twoway ///
              (scatter MM_$main_regressor TP [aw = total_SalesRevenue_EUR_per_Year] if groups_${main_regressor}_${main_regressor} == `i', title("`Identifier_graph'", color(maroon)) ytitle(Material Margin (%)) mcolor(navy) msymbol(circle_hollow)) ///
              (scatter MM_$main_regressor TP if groups_${main_regressor}_${main_regressor} == `i' & total_SalesRevenue_EUR_per_Year == 0, msize(tiny) mcolor(navy) msymbol(circle)) ///
              (scatter MM_TP TP [aw = total_SalesRevenue_EUR_per_Year] if groups_${main_regressor}_${main_regressor} == `i', mcolor(red) msymbol(X)) ///
              (scatter MM_TP TP if groups_${main_regressor}_${main_regressor} == `i', msize(tiny) mcolor(red) msymbol(circle))
      Unbenannt2.PNG


      Any ideas, what else to try?
      Last edited by Paul Shlapa; 02 Feb 2023, 05:26.

      Comment


      • #4
        For some reason, when i exclude lines, that go from minimum observation on x-axis to the same value (basically range(min min)), the graph is being fully shown.

        But i still do not understand why any line, irrespective of its range (here 350 350) should affect the graph output in the way as shown at the beginning of this post?

        Code:
        capture noisily twoway ///
                (scatter MM_$main_regressor TP [aw = total_SalesRevenue_EUR_per_Year] if groups_${main_regressor}_${main_regressor} == `i', title("`Identifier_graph'", color(maroon)) ytitle(Material Margin (%)) xtitle(TP (€)) mcolor(navy) msymbol(circle_hollow)) ///
                (scatter MM_$main_regressor TP if groups_${main_regressor}_${main_regressor} == `i' & total_SalesRevenue_EUR_per_Year == 0, msize(tiny) mcolor(navy) msymbol(circle)) ///
                (scatter MM_TP TP [aw = total_SalesRevenue_EUR_per_Year] if groups_${main_regressor}_${main_regressor} == `i', mcolor(red) msymbol(X)) ///
                (scatter MM_TP TP if groups_${main_regressor}_${main_regressor} == `i', msize(tiny) mcolor(red) msymbol(circle)) ///
                (${function_`a'}, range (`m_1_`a'' `m_2_`a'') lcolor(maroon)) || (${function_`a'_2}, range (`m_2_`a'' `m_max') lcolor(maroon)) ///
                (${function_`b'}, range (`m_1_`b'' `m_2_`b'') lcolor(maroon)) || (${function_`b'_2}, range (`m_2_`b'' `m_max') lcolor(maroon)) ///
                (${function_`v'}, range (`m_1_`v'' `m_2_`v'') lpattern(dash) lcolor(white)) || (${function_`v'_2}, range (`m_2_`v'' `m_max') lpattern(dash) lcolor(white)), ///
                legend(off)
        Unbenannt3.PNG
        Last edited by Paul Shlapa; 02 Feb 2023, 06:50.

        Comment


        • #5
          It is hard to help further as

          we do not have access to your data

          we have no way of knowing earlier definitions of local and global macros

          (in my case) I can't read through code like that and easily filter out what is secondary and what is problematic without a lot of experiment

          In addition, you appear to be using some non-default scheme, which may be relevant.

          If you want to pursue this further we need please a self-contained reproducible example so that we can copy code from here and follow on our copy of Stata

          Comment

          Working...
          X