是否可以在已躲避的条形图中垂直调整标签?

时间:2019-04-14 15:11:51

标签: r ggplot2

我想降低躲避的条形图中标签的高度,以使其不在条形边缘上。

我尝试在position_dodge()中使用height =,但是由于height不是position_dodge()中的参数,因此会出现错误“未使用的参数”。这是我的代码:

newdata <- read.table(text = "2010 2018
healthcare 0.09940358 0.09256198
allsectors 0.14713699 0.15306588", sep = " ", header = TRUE)

library(reshape)
datnew <- melt(cbind(newdata, ind = rownames(newdata)), id.vars = c('ind'))
library(ggplot2)
library(scales)
library(dplyr)

ggplot(datnew, aes(x = variable, y = value, fill = ind)) + 
geom_col(position = "dodge", colour = 'black') + 
geom_text(size = 3.5, position = position_dodge(width=1), aes(label = 
scales::percent(value))) + 
scale_x_discrete(labels = c('2010', '2018')) + 
scale_y_continuous(labels = percent_format()) + 
scale_fill_manual(name = "sector" , values = c("brown3", "darkgrey")) +
xlab('Year') + 
ylab('% of workforce') + 
ggtitle('figure 4', subtitle = 'Workers under the age of 25') 
theme_bw() +
theme(plot.title=element_text(lineheight = NULL, hjust=0.5, face="bold", 
color="black", size=16), plot.subtitle = element_text(lineheight = NULL, 
hjust=0.5, color = 'black', size=14), panel.border = element_blank(), 
panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
axis.line = element_line(colour = "black")) + expand_limits(y = 0)

如前所述,我想降低标签在条形图中的位置。

0 个答案:

没有答案