我在我的previous question中的回答中得到以下数据:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(code year) str56 products
15328 2007 "Coca-Cola, Coca-Cola Diet"
15328 2008 "Pepsi"
15328 2010 "Pepsi Diet, Dr Pepper"
15328 2011 "7 Up"
15328 2012 "Aquafina, Fanta"
15328 2013 "Amp Energy, Manhattan Special, Jolt Cola, Mountain Dew"
15328 2014 "Cocofina, Highland Spring"
15328 2015 "Lucozade"
15328 2016 "Ribena"
15328 2017 "Classic Cola, Red Cola"
16564 2009 "Dove, The Body Shop"
16564 2010 "L'Occitane"
16564 2011 "Dove Sensitive"
16564 2015 "Paul Mitchell, Aveda"
16897 2007 "L'eau D'issey"
16897 2010 "Versace Eros, Dolce & Gabbana, Paul Sebastian"
16897 2011 "Ck One, Versace Man"
16897 2015 "Jean Paul Gaultier"
16897 2016 "Boss No. 6"
16897 2018 "Aramis"
17874 2007 "Adidas"
17874 2011 "Airness"
17874 2013 "Reebok"
17874 2014 "Nike, Caterpillar"
17874 2015 "Columbia sportswear, Asics"
end
我一直在尝试使用以下命令创建图形:
twoway scatter code year
如何在图形中显示字符串标签?
答案 0 :(得分:1)
长字符串的长度在各种图形中作为标签可能特别成问题。这是因为它们倾向于相互重叠,从而产生混乱的结果。
但是,以下内容可以满足您的需求:
twoway scatter code year, yscale(range(14900 18100)) ylabel(15328 16564 16897 ///
17874, labsize(vsmall) angle(horizontal)) ytitle("Code") xscale(range(2006 2018)) ///
xtitle("Year") xlabel(2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018, ///
labsize(vsmall) grid) mlabel(products) mlabposition(6) mlabangle(20) mlabgap(0) ///
mlabsize(vsmall) msymbol(none) graphregion(color(white))
您还可以通过组合不同代码的散点图对标签进行颜色编码:
twoway scatter code year if code == 15328, mlabel(products) mlabposition(6) ///
mlabangle(20) mlabgap(0) mlabsize(vsmall) msymbol(none) mlabcolor("cranberry") || ///
scatter code year if code == 16564, mlabel(products) mlabposition(6) ///
mlabangle(20) mlabgap(0) mlabsize(vsmall) msymbol(none) mlabcolor("green") || ///
scatter code year if code == 16897, mlabel(products) mlabposition(6) ///
mlabangle(20) mlabgap(0) mlabsize(vsmall) msymbol(none) mlabcolor("ebblue") || ///
scatter code year if code == 17874, yscale(range(14900 18100)) ///
ylabel(15328 16564 16897 17874, labsize(vsmall) angle(horizontal)) ytitle("Code") ///
xscale(range(2006 2018)) xtitle("Year") xlabel(2007 2008 2009 2010 2011 2012 2013 ///
2014 2015 2016 2017 2018, labsize(vsmall) grid) mlabel(products) mlabposition(6) ///
mlabangle(20) mlabgap(0) mlabsize(vsmall) msymbol(none) mlabcolor("maroon") ///
graphregion(color(white)) legend(off)
也许是这样的: