Example of in-bar labels using geom_label()
library(ggthemes)
library(ggplot2)
library(dplyr)
data("mtcars")
metric_cars <- mtcars %>%
mutate(
Engine = round(disp / 61.024),
Economy = round(100 * 3.785411784 / (1.609344 * mpg), 1)
)
mean_cyl_mileage <- metric_cars %>%
group_by(Engine) %>%
summarise(avg_economy = round(mean(Economy),1))
ggplot(mean_cyl_mileage, aes(x=factor(Engine),y=avg_economy, fill = factor(Engine))) +
geom_col() +
theme_excel_new() +
geom_label(
aes(label=format(avg_economy, nsmall=1)),
colour='white',
fontface='bold',
vjust = 0.5
) +
scale_color_brewer(palette = "Pastel1") +
theme(legend.position = "none") +
theme(axis.title = element_text()) +
ylab('Fuel Consumption (L/100km)\n') +
xlab('\nEngine Size (to nearest litre)') +
ggtitle('Fuel Consumption by Engine Size')