R图形编码:背靠背直方图

时间:2014-09-06 00:50:52

标签: r plot

我正在努力完成的任务意味着创建一个背靠背直方图的图,如下面的图片所示。

http://imgur.com/EKDwuH8 (I don't have high enough REP to post direct images)

首先,首先,是的,这是一个由教授提供的作业,我真的想要了解图形而不仅仅是获得产生这个功能的代码,因为那时我仍然会一样无用,无论如何,无视分配的目的。

到目前为止,使用布局功能,我创建了一个7面板布局,使用2乘2矩阵,因为当使用奇数矩阵时,我在我的绘图之间得到一个多余的中心面板,我不知道如何删除,所以这是我的布局:

m = rbind(c(0,0),c(7,7),c(5,6),c(4,4),c(1,2),c(3,3),c(0,0))
layout(m,widths = c(1,1,1,1,1,1,1),heights = c(1,0.56,0.5,0.5,4,0.5,1))
layout.show(7)

我已经单独绘制了女性和男性数据:

Female =
c(85, 71, 52, 56, 19, 1, 4, 4, 62, 3, 50, 87, 58, 92)

Male = 100- Female

Subject =
c("Humanities", "Social Sciences", "Science", "Economics", "Engineering", 
"Construction", "Electrical Engineering", "Vehicles and Transport", 
"Business Studies", "Industrial Engineering", "Agriculture", 
"Nursing (Care)", "Catering", "Nursing")

xlim = c(0,1.06*max(Female,Male))
ylim = c(0,length(Subject))

yt = 1:length(Subject)
yb = yt - 1

plot.new()
plot.window(xlim = rev(xlim), ylim = ylim,
        xaxs = "i", yaxs = "i")
rect(0, yb, Male, yt, col = "lightgray")
axis(1)
box()

plot.new()
plot.window(xlim = xlim, ylim = ylim,
        xaxs = "i", yaxs = "i")
rect(0, yb, Female, yt, col = "lightgray")
axis(1)
box()

现在,我的主要帮助是首先,让分类名称跨越条形,我不确定如何标记条形本身,当它们在情节本身,然后如何建立图例。

非常感谢任何正确方向的指示。

由于

0 个答案:

没有答案