下圖顯示了我用下面的代碼創建的圖表。我強調了缺失或重疊的標籤。有沒有辦法告訴ggplot2不重疊標籤?如何防止兩個標籤在條形圖中重疊?
week = c(0, 1, 1, 1, 1, 2, 2, 3, 4, 5)
statuses = c('Shipped', 'Shipped', 'Shipped', 'Shipped', 'Not-Shipped', 'Shipped', 'Shipped', 'Shipped', 'Not-Shipped', 'Shipped')
dat <- data.frame(Week = week, Status = statuses)
p <- qplot(factor(Week), data = dat, geom = "bar", fill = factor(Status))
p <- p + geom_bar()
# Below is the most important line, that's the one which displays the value
p <- p + stat_bin(aes(label = ..count..), geom = "text", vjust = -1, size = 3)
p
您可以在特定座標處繪製文本。這不是最好的方法,但它會完成工作。 – 2013-04-21 02:47:52
@Ricardo:這是一個想法,但酒吧可以是任何高度。 – Martin 2013-04-22 14:58:11