问题
I have two functions y=5*x+3
and y=8*x+2
.
After i type the command:
graph twoway (function y=5*x+3) (function y=8*x+2)
I can use the graphics editor to write text near the intersection of the two lines.
However, I would not like to do this all the time.
Is there a way to create the graph with the text without adding it later?
回答1:
There is a text
option for the graph twoway
command that does this.
First, you obviously need to solve for x
and then get the value of y
:
5x + 3 = 8x + 2
x = (-3 + 2) / -3
x = 0.333
y = 8 * 0.333 + 2
y = 4.664
With both coordinates at hand, you just need to add the textbox in your twoway
command:
twoway (function y=5*x+3) (function y=8*x+2), text(4.664 0.333 "Intersection", placement(11))
See added text options in the Stata manual for more details.
EDIT:
Alternatively, you could also use a marker:
twoway (function y=5*x+3) (function y=8*x+2) (scatteri 4.664 0.333 (11) "Intersection")
The entry on graph twoway scatteri in the Stata manual provides additional information.
来源:https://stackoverflow.com/questions/51987747/insert-text-in-a-specific-location-of-a-graph