如何在直方图中调整其中一个条形标签?

时间:2018-01-04 04:29:24

标签: r ggplot2

我的代码在这里

Yr = c("2016","2017","2016","2017","2016","2017")
Type = c("A","A","B","B","C","C")
Value = c(73,183,160,476,11,73)
Percentage = c(29.92,25.00,65.57,65.03,4.51,9.97)
p1Data <- data.frame(Yr,Type,Value,Percentage)

library(ggplot2)

p1 <- ggplot(p1Data, aes(Type, Value, fill = Yr)) +
  geom_bar(stat = "identity", position = position_dodge(width = 0.9)) +
  theme(axis.title.x = element_blank(), plot.title = element_text(hjust = 0)) +
  geom_text(aes(label = paste(Value, paste(Percentage, "%"), sep = "\n"), y = Value), size = 4, vjust = 1.5, position = position_dodge(width = 0.9)) +
  ggtitle("2016 V.S. 2017")  +
  labs(fill = "Catagory")

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以在else: question = random_question() 中将vjust = 1.5更改为vjust = "inwards"

geom_text

enter image description here