Совместите галочки с барами - R - PullRequest
1 голос
/ 11 апреля 2020

Как выровнять тики по столбцам в следующем коде. Оцените!

Код

barplot(Freq, ylab="Frequency",xaxt="n")
axis(1, las=2, at=1:20, labels=c("[0,70]","(70,140]","(140,210]","(210,280]","(280,350]","(350,420]","(420,490]","(490,560]","(560,630]","(630,700]","(700,770]","(770,840]","(840,910]","(910,980]","(980,1050]","(1050,1120]","(1120,1190]","(1190,1260]","(1260,1330]","(1340,1400]"),cex.axis=0.8)
mtext(side = 1, text = "Range of Feedbacck Length (Character)", line = 4)

Данные (называемые Freq)

structure(c(`(0,70]` = 2435L, `(70,140]` = 6472L, `(140,210]` = 5635L, 
`(210,280]` = 4399L, `(280,350]` = 2426L, `(350,420]` = 2155L, 
`(420,490]` = 1550L, `(490,560]` = 763L, `(560,630]` = 404L, 
`(630,700]` = 249L, `(700,770]` = 138L, `(770,840]` = 111L, `(840,910]` = 63L, 
`(910,980]` = 22L, `(980,1.05e+03]` = 58L, `(1.05e+03,1.12e+03]` = 107L, 
`(1.12e+03,1.19e+03]` = 154L, `(1.19e+03,1.26e+03]` = 142L, `(1.26e+03,1.33e+03]` = 143L, 
`(1.33e+03,1.4e+03]` = 68L), .Dim = 20L, .Dimnames = structure(list(
    c("(0,70]", "(70,140]", "(140,210]", "(210,280]", "(280,350]", 
    "(350,420]", "(420,490]", "(490,560]", "(560,630]", "(630,700]", 
    "(700,770]", "(770,840]", "(840,910]", "(910,980]", "(980,1.05e+03]", 
    "(1.05e+03,1.12e+03]", "(1.12e+03,1.19e+03]", "(1.19e+03,1.26e+03]", 
    "(1.26e+03,1.33e+03]", "(1.33e+03,1.4e+03]")), .Names = ""), class = "table")

1 Ответ

1 голос
/ 11 апреля 2020

Вы можете получить позицию, сохранив объект барплота:

# the par is to have more space from the bottom, so you can see the labels
par(mar=c(8,3,3,3))
bp = barplot(Freq, ylab="Frequency",xaxt="n")
axis(1, las=2, at=bp, labels=names(Freq),cex.axis=0.8)
mtext(side = 1, text = "Range of Feedback Length (Character)", line = 4)

enter image description here

...