【问题标题】:Add bar labels to horizontal histogram in Stata在Stata中将条形标签添加到水平直方图
【发布时间】:2016-11-15 02:20:27
【问题描述】:

有没有人知道在 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))

产生 this

【问题讨论】:

    标签: histogram stata


    【解决方案1】:

    您没有提供可重现的示例。请参阅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))
    

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

    顺便说一句,您的类别缺乏任何明显的顺序,这使得它在许多标准上都不是一个糟糕的图表。从最频繁到最少排序是一种明显的可能性。

    【讨论】:

    • 谢谢,尼克!我必须承认,我对 stackoverflow 还很陌生,所以我不确定附加数据的最佳方式。我已尝试添加要为其创建直方图的变量中的值,但如果这不是您的想法,请告诉我!
    • 对于 Stata 问题,您需要任何人都可以阅读的示例数据集(例如 sysusewebuse)或示例提供的自包含数据集。 ssc inst dataex 为后者安装专用命令。
    • 您现在的数据可以通过一些努力读入,但我认为工程太像无趣的艰苦工作。 (如果它变得不真实,我将删除此评论。)(此外,为什么我的答案不是您想要的变量名翻译?)
    猜你喜欢
    • 2022-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 2022-01-16
    • 1970-01-01
    • 2019-03-08
    相关资源
    最近更新 更多