在Stata中将条形标签添加到水平直方图中

时间:2016-11-15 02:20:28

标签: histogram stata

有没有人知道在Stata的水平直方图中在条形图上添加标签的解决方法?在帮助文件中,它表示水平和addlabels命令不能一起工作,但我希望有一个很好的方法来做到这一点!任何见解都将非常感谢!

我的数据如下: con_physical

Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to find premises CONNECTED TO SERVICES
Difficult to find premises in an optimal LOCATION
Insufficient supply of WATER
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to find premises in an optimal LOCATION
Difficult to FINANCE equipment
Low level of AUTOMATION
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Unreliable supply of ELECTRICITY
Difficult to FINANCE equipment
Unreliable supply of ELECTRICITY
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to find premises CONNECTED TO SERVICES
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to find premises CONNECTED TO SERVICES
Difficult to find premises CONNECTED TO SERVICES
Difficult to FINANCE equipment
Unreliable supply of ELECTRICITY
Difficult to find premises in an optimal LOCATION
Difficult to FINANCE equipment
Difficult to find premises CONNECTED TO SERVICES
Low level of AUTOMATION
Difficult to FINANCE equipment
Difficult to find premises that are not in good CONDITION
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to FINANCE equipment
Difficult to find premises in an optimal LOCATION
Difficult to find premises that are not in good CONDITION
Difficult to find premises that are not in good CONDITION
Difficult to find premises CONNECTED TO SERVICES
Difficult to find premises that are not in good CONDITION
Low level of AUTOMATION
Low level of AUTOMATION
Difficult to find premises CONNECTED TO SERVICES
Unreliable supply of ELECTRICITY
Low level of AUTOMATION
Low level of AUTOMATION
Low level of AUTOMATION
Difficult to find premises in an optimal LOCATION
Low level of AUTOMATION
Difficult to find premises CONNECTED TO SERVICES
Difficult to FINANCE equipment

我的代码是

hist con_physical, addlabels title("Biggest Physical Resource Constraint", size(small)) xtitle("Percent of Sample") ytitle("") horizontal discrete percent     bcolor(navy) yla(2/8, valuelabel labsize(vsmall) angle(0))

生成此

1 个答案:

答案 0 :(得分:0)

您没有提供可重现的示例。有关指导,请参阅https://stackoverflow.com/help/mcve。为什么三个(也就是三个)标签出现以及它们与直方图的关系不清楚,无法访问您的数据。

我不会在这里使用histogram作为首选。对于具有自己的值标签的类别,graph hbar在大多数方面更灵活。

此示例显示了一些可以在Stata中使用的代码的技术:

sysuse auto, clear
graph hbar, over(rep78) blabel(total, format(%2.1f) pos(base)) bar(1, bfcolor(none))
more 
contract rep78
graph hbar (asis) _freq, over(rep78) blabel(total, pos(base)) bar(1, bfcolor(none))

在此示例中,没有值标签,但如果它们存在则会显示它们。

顺便提一下,对您的类别缺乏任何明显的排序使得它成为许多标准的糟糕图表。从最常见到最少排序是一个明显的可能性。