R 图表布局和条形图标签

R 图表布局和条形图标签,r,layout,charts,R,Layout,Charts,当前正在尝试创建此 在将图表放入1号框时遇到一些困难 也不知道如何标签内的酒吧,任何帮助将不胜感激! 到目前为止,我掌握的代码是 Subject = c("Humanities", "Social Sciences", "Science", "Economics", "Engineering", "Construction", "Electrical Engineering", "Vehicles and Transport", "Business Studies", "

当前正在尝试创建此

在将图表放入1号框时遇到一些困难

也不知道如何标签内的酒吧,任何帮助将不胜感激! 到目前为止,我掌握的代码是

Subject =
  c("Humanities", "Social Sciences", "Science", "Economics", "Engineering", 
    "Construction", "Electrical Engineering", "Vehicles and Transport", 
    "Business Studies", "Industrial Engineering", "Agriculture", 
    "Nursing (Care)", "Catering", "Nursing")
Female =
  c(85, 71, 52, 56, 19, 1, 4, 4, 62, 3, 50, 87, 58, 92)
Area =
  c("Theory", "Theory", "Theory", "Theory", "Theory", "Vocational", 
    "Vocational", "Vocational", "Vocational", "Vocational", "Vocational", 
    "Vocational", "Vocational", "Vocational")
Male = 100 - Female

Data = data.frame (Subject = Subject, Area = Area, 
                     Female = Female, Male = Male)
orderFemale = order (Data$Female)
Gender1991 = Data[orderFemale, ]
head (Gender1991)

##Create a plotting layout. Check with layout.show then remove
layout (matrix (c (0, 0, 0, 0,
               0, 5, 5, 0,
               0, 4, 3, 0,
               0, 2, 1, 0,
               0, 0, 0, 0),
            nc = 4, byrow = TRUE),
    widths = c (lcm(1), 1, 1, lcm(1)),
    heights = c (lcm(1), lcm(1), lcm (1),
                 1, lcm(1)))
layout.show (5)
par (mar = rep (0, 4))

xlim = c (0, 100)
ylim = c (0, length (Gender1991$Female))
yt = 1:length (Gender1991$Female)
yb = yt - 1

##Female data plotting
plot.new()
plot.window (xlim = xlim, ylim = ylim, xaxs = "i", yaxs = "i")
rect (0, yb, Gender1991$Female, yt)
axis (1)
axis (3)
box()

##Male data plotting
plot.new()
plot.window (xlim = rev(xlim), ylim = ylim, xaxs = "i", yaxs = "i")
rect (0, yb, Gender1991$Male, yt)
axis (1)
axis (3)
box()

label.panel = 
  function (label, xadj = .5, yadj = .5, cex = 1,
        font = 1, col = "black", angle = 0){
plot.new()
plot.window (xlim = c (0, 1), ylim = c (0, 1), xaxs = "i", yaxs = "i")
text (xadj, yadj, label, font = font, cex = cex, col = col,
      adj = c (xadj, yadj), srt = angle)
  }

genderLabel = c ("Number of girls", "Number of boys")
heading = "Intake by sex into three-year courses at upper secondary school 1991"

label.panel (genderLabel[1], xadj = 1)
label.panel (genderLabel[2], xadj = 0)
label.panel (heading, font = 2)
但这段代码目前使图形占据了整个区域,并存在一些其他格式问题。
如果您能给我一些建议,我将不胜感激,谢谢您。我不确定是否希望在这方面提供帮助,但是 我注意到在图表上,轴标记为25、50、75和100

调整你的状态以匹配这是你能做的

##Female data plotting
plot.new()
plot.window (xlim = xlim, ylim = ylim, xaxs = "i", yaxs = "i")
rect (0, yb, Gender1991$Female, yt)
axis (1)
axis (3)
box()
在每个轴中,更改为 轴1,at=破折号 其中,破折号是0、25、50、75、100的向量

希望这有帮助