Установите разные позиции меток осей и меток на линейке

I would like to realign/offset the x-axis and associated tick marks of a barplot. This should be simple but I am having trouble finding an answer. Below is some example data with 24 categories.

xval = c(1:24)
count = c(0.03,0.03,0.08,0.06,0.11,0.4,0.3,0.5,0.5,0.6,0.4,0.1,0.1,0.4,0.2,0.1,0.06,0.05,0.03,0.02,0.01,0.03,0.01,0.02)
df = as.data.frame(cbind(xval, count))

I can easily produce a barplot with tick marks aligned at the bar midpoints using the below code:

mp <- barplot(df$count, space=0, axes=FALSE) 
axis(side=2, pos=-0.2)
axis(side=1, at =mp, labels=df$xval)

I can also shift the entire x-axis (labels and ticks) to align with the outside of bars using the below (although this now fails to incorporate the last bar into the axis):

axis(side=1, at =mp-0.5, labels=df$xval)

While I would like the x-axis and associated tick marks to be aligned with the bar boundaries (i.e. a tick mark on either side of the bar instead of in the centre), I want the x-axis labels to remain at the bar midpoints. Is there an easy way to achieve this?

4 голоса | спросил Emily 28 +04002013-10-28T19:20:58+04:00312013bEurope/MoscowMon, 28 Oct 2013 19:20:58 +0400 2013, 19:20:58

1 ответ

Это то, что вы ищите?введите описание изображения здесь
ответил Henrik 28 +04002013-10-28T19:25:55+04:00312013bEurope/MoscowMon, 28 Oct 2013 19:25:55 +0400 2013, 19:25:55

Похожие вопросы

Популярные теги

security × 330linux × 316macos × 2827 × 268performance × 244command-line × 241sql-server × 235joomla-3.x × 222java × 189c++ × 186windows × 180cisco × 168bash × 158c# × 142gmail × 139arduino-uno × 139javascript × 134ssh × 133seo × 132mysql × 132