R中的geom_bar图表由于错误而未显示轴标签

时间:2018-11-27 16:22:58

标签: r ggplot2 geom-bar

我试图在R中创建一个非常简单的条形图。但是,我的轴标题存在问题。我不断收到错误消息:

  

unit(rep(just $ hjust,n),“ npc”)中的错误:     “ x”和“ units”的长度必须大于0

我无法理解此错误的发生位置和发生方式

charac<-c('A','C','B','E','D')
total<-c(100,200,150,125,225)
df<-data.frame(charac,total)
df<-df[order(-df$total),]
lvls<-df$charac
df$charac<-factor(df$charac,levels=lvls,order=TRUE)
    p<-ggplot(data=df,aes(x=charac,y=total))+
  geom_bar(stat='identity',fill='steelblue')+
  geom_text(aes(label=paste0(total,'m')),vjust=-0.5,size=4)+
  xlab('Characters')+
  ylab('Totals')+
  scale_y_continuous(breaks = seq(0, 250, by = 50))+
  theme_void() +
  theme(
    axis.title.x = element_text(size = 11), # if I comment here and on axis.title.y it works, but I need to show those titles
    axis.title.y = element_text(size = 11),
    plot.margin = unit(c(0.5,0.1,1,0.1), "cm"),
    legend.position = 'none',
    plot.background = element_rect(fill = "transparent", colour = NA),
    legend.background = element_rect(fill = "transparent"),
    legend.box.background = element_rect(fill = "transparent")
  )
p

0 个答案:

没有答案