0

can anyone tell me how to adjust the x label position? I want to put the label(df1$Value) on each bar's head? Thanks for your help! Here is my code

Yr <- c("2016","2017","2016","2017","2016","2017")
Type <- c("A","A","B","B","C","C")
Value <- c(73,183,160,476,11,73)
p1Data <- data.frame(Yr,Type,Value)
p1Data$Yr <- as.character(p1Data$Yr)
p1Data <- transform(p1Data, Type = factor(p1Data$Type, levels = c("A","B","C")))

library(ggplot2)

p1 <- ggplot(p1Data,aes(Type,Value,fill=Yr))+geom_bar(stat="identity",position='dodge')+ theme(axis.title.x=element_blank())+ geom_text(aes(label=Value,vjust=1.5))  

enter image description here

www
  • 38,575
  • 12
  • 48
  • 84
Let's Yo
  • 335
  • 1
  • 3
  • 11

1 Answers1

0

Use position = position_dodge(width = ?) to set the width of dodge. Do not put this argument in the aes call.

library(ggplot2)

ggplot(p1Data,aes(Type,Value,fill=Yr))+
  geom_bar(stat="identity",position='dodge')+ 
  theme(axis.title.x=element_blank())+ 
  geom_text(aes(label = Value), vjust = 1.5, position = position_dodge(width = 0.9)) 

enter image description here

www
  • 38,575
  • 12
  • 48
  • 84