在没有ggplot的R中创建堆积柱图

时间:2015-08-06 06:48:09

标签: r bar-chart stacked

我有数据

    equip ballots  freq %Undercounts
1   LEVER  427780 17016         3.98
2 OPTICAL 1436159 39090         2.72
3   PAPER    3454   113         3.27
4   PUNCH  823921 38462         4.67

我想在X轴上绘制设备。每个装备的选票应为100%。频率应该是条形的百分比,并表示为选票的百分比。

我尝试了barplot和格子图。但我收到一些错误,似乎我的数据不符合格式。有人可以帮助我解决我可能遗失的问题。

感谢。

1 个答案:

答案 0 :(得分:0)

使用lattice

完成此操作非常简单
barchart(freq/ballots + (ballots-freq)/ballots ~ equip, tab, stack=TRUE)

enter image description here

基础图形需要更多代码和一些模糊的参数调整才能看起来很好

attach(tab)
barplot(rbind(freq/ballots, 1), width=.8, space=.25)
mtext(equip, side=1, at=1:nrow(tab)-.4)

enter image description here