繁体   English   中英

如何将R barplot()中的小节居中

[英]How to center bars in R barplot() around ticks

我仍在与R类似的问题苦苦挣扎:在小节中点不是居中的wrt bar

我想制作一个小节,但我的小节居中。 但是,如果按照下面所述的方式进行操作,则我的小节将向右移动1.2而不是1点。

我需要将条形图居中,以便于在条形图上方便地放置标签,因此我想问问您是否有这样做的方法。

Part1 <- c(2,4,9,18,20)
Part2 <- c(2,5,1,4,0)
counts <- rbind(Part1, Part2)
colnames(counts) <- c(1,2,3,4,5)

x <- barplot(counts, 
  axes = FALSE,  
  col = c("darkgreen", "red"),
  xlim = c(0, 5*1.50),
  ylim = c(0,60)
)
axis(side = 2, pos = 0) 
axis(side = 1, at = c(0,1,2,3,4,5), tick = TRUE)
Part1 <- c(2,4,9,18,20)
Part2 <- c(2,5,1,4,0)
counts <- rbind(Part1, Part2)
colnames(counts) <- c(1,2,3,4,5)

x<-barplot(counts, 
  axes = FALSE,  
  space = 0,         
  col = c("darkgreen", "red"),
  xlim = c(0, 5*1.50),
  ylim = c(0,60)
)

#create positions for tick marks, one more than number of bars
ticks <- seq_len(length(counts) + 1)
axis(side = 2, pos = 0)
#adding x-axis with offset positions, with ticks, but without labels
axis(side = 1, at = ticks - 0.5, labels = FALSE)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM