Announcement

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

  • Puhong Yu
    started a topic How to remove the left blank margin in a plot

    How to remove the left blank margin in a plot

    I want to make a simple plot representing a consumer's consumer surplus in Stata. By default, Stata leaves some blank margin in the left, but this makes the graph quite strange (the triangle is not closed).I searched Statalist and tried many ways to remove it, including using xscale and plotregion(margin(zero)), but none of them worked. Could anyone tell me how to achieve this (removing the blank between AB and the y axis in the attached graph)? Many thanks in advance.

    The code I wrote is as follows:
    clear
    Code:
    set obs 100
    generate q=_n-1
    generate p=50
    generate cons=100-q
    twoway (line cons q) (line p q, lpattern(dash)), xline(25, lpattern(dash)) xtitle("Consumption") ytitle("Price") text(51 51 "O", place(nw)) text(50 1 "A", place(s)) text(100 1 "B", place(n)) xlabel(25 "Garbage") ylabel(50 "p" 100 "a") title("Free Disposal of Garbage") xscale(range(0 105)) legend(off) graphregion(margin(zero))
    Attached Files

  • Puhong Yu
    replied
    Thank you very much. It works perfectly. Scott Merryman

    Leave a comment:


  • Andrew Musau
    replied
    Good find Scott Merryman!

    Leave a comment:


  • Scott Merryman
    replied
    Adding -plotregion(margin(zero)) seems to work:

    Code:
    clear
    set obs 100
    generate q=_n-1
    generate p=50
    generate cons=100-q
    twoway (line cons q) /// 
        (line p q, lpattern(dash)), xline(25, lpattern(dash)) ///
         xtitle("Consumption") ytitle("Price") text(51 51 "O", place(nw)) ///
         text(50 1 "A", place(s)) text(100 1 "B", place(n)) /// 
         xlabel(25 "Garbage") ylabel(50 "p" 100 "a") /// 
         title("Free Disposal of Garbage")  /// 
         legend(off) xscale(range(0 105)) graphregion(margin(zero)) /// 
         scheme(s2mono)   plotregion(margin(zero))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.8 KB
ID:	1522030

    Leave a comment:


  • Andrew Musau
    replied
    Short answer, you cannot. You have to suppress the axes and mimic them using lines. This has not been tidied up.

    Code:
    set obs 100
    generate q=_n-1
    generate p=50
    generate cons=100-q
    
    twoway (line cons q) (line p q, lpattern(dash)) (scatteri 105 -0.5 "-" 105 -2 "a" ///
    55 -0.5 "-" 55 -2 "p" 3 25 "I" -0.5 25 "Garbage", mlabpos(6) msymbol(none) ///
    mlabsize(*1.25) mlabcolor(black)), xline(0, lc(black) lw(thin)) xscale(off) yline(0, lc(black) ///
    lw(thin)) yscale(off) xline(25, lpattern(dash)) xtitle("Consumption") ytitle("Price")  ///
    text(51 51 "O", place(nw)) text(50 1 "A", place(s)) text(100 1 "B", place(n)) xlabel(25 "Garbage") ///
    ylabel(50 "p" 100 "a") title("Free Disposal of Garbage")  legend(on order(0) nobox ///
    region(lstyle(none))) graphregion(margin(zero))




    Click image for larger version

Name:	Graph.png
Views:	1
Size:	56.4 KB
ID:	1522027

    Leave a comment:

Working...
X