Suppose I have a data like this
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str5 id int(year data) "a123" 2015 190 "a123" 2016 172 "a123" 2017 227 "as433" 2015 232 "as433" 2016 167 "as433" 2017 119 "te398" 2015 193 "te398" 2016 239 "te398" 2017 156 "be372" 2015 185 "be372" 2016 136 "be372" 2017 148 "cd923" 2015 135 "cd923" 2016 213 "cd923" 2017 255 "tl102" 2015 296 "tl102" 2016 237 "tl102" 2017 236 end
Code:
local list "a123 as433 te398 cd923" local j=0 foreach i of local list { local j=`j'+1 local graphs `graphs' (line data year if id == "`i'", graphregion(fcolor(gs16)) legend(label(`j' "`i'")) ytitle("Data") xtitle("Year")) } graph twoway `graphs'
0 Response to Change legend automatically in graph
Post a Comment