intro <- tibble(category = c("a", "b"), height = c(1,1), name = c("White", "Black, Asian, Mixed or other Ethnic group (BAME)"))
ggplot(intro) +
geom_bar(aes(category, height, fill = name), stat = "identity", width = 0.5) +
scale_fill_manual(values = c("dark blue", "light blue")) +
geom_text(aes(x = category, y = height, group = category, label = str_wrap(name, 15), colour = name),
position = position_stack(vjust = 0.5), family = "Source Sans Pro", fontface = "bold", size = 4) +
scale_colour_manual(values = c("white", "black")) +
theme_minimal() +
theme(text= element_text(family = "Source Sans Pro"),
plot.margin=grid::unit(c(0,0,0,0), "mm"),
aspect.ratio = 0.22,
legend.position = "none",
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank())
ggplot(filter(intro_data, Measure == "UK"),
aes(x = "1", y = Value, fill = Ethnicity_binary)) +
geom_bar(stat='identity', width = 0.75) +
coord_flip() +
scale_y_continuous(limits = c(0, 100)) +
geom_hline(yintercept = 86.4, linetype = "dotted", size = 1.5) +
# Colour scheme
scale_fill_manual(values = c("dark blue", "light blue")) +
# Customise theme
theme_minimal() +
theme(text= element_text(family = "Source Sans Pro"),
plot.margin=grid::unit(c(0,0,0,0), "mm"),
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
legend.position = "none",
plot.caption = element_text(size = 8, vjust = -5, colour = "dark grey")) +
# Create dynamic % labels on each bar
geom_text(aes(group = Value, label = label, colour = Ethnicity_binary),
position = position_stack(vjust = 0.5),
family = "Source Sans Pro", fontface = "bold", size = 4.5) +
scale_colour_manual(values = c("white", "black")) +
labs(caption = "Year: 2011. Region: UK. Source: Office for National Statistics.")
# Plot
p <- ggplot(data) +
## Add the stacked bar
geom_bar_interactive(aes(x = as.factor(id), y = Value, fill = Ethnicity_binary,
tooltip = paste(label, " ", Ethnicity_binary)),
stat = "identity", width = 0.3) +
scale_fill_manual(values = c("dark blue", "light blue")) +
geom_hline(yintercept = 86.4, linetype = "dotted", size = 1) +
theme_minimal() +
theme(text= element_text(family = "Source Sans Pro"),
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
legend.position = "none",
plot.margin = unit(c(0,0,0,0), "mm")) +
coord_polar() +
geom_text(data = label_data,
aes(x = id, y = (tot/tot)*105, label = str_wrap(Measure, 15), hjust = hjust),
angle = label_data$angle,
colour = "black", size = 1.75, family = "Source Sans Pro", fontface = "bold", inherit.aes = FALSE) +
## Change y limits to allow space for base line information
ylim(-100,max(label_data$tot + 5, na.rm=T)) +
## Add base line information
geom_segment(data = base_data,
aes(x = start, y = -5, xend = end, yend = -5),
colour = "dark grey", size = 1, lineend = "round", inherit.aes = FALSE) +
geom_text(data = base_data,
aes(x = title, y = -20, label = str_wrap(category, 1)),
angle = c(-15, -50, 90, 45, 0, -60, -290, -335),
colour = "dark grey", size = 2, family = "Source Sans Pro", fontface = "bold", inherit.aes = FALSE)
girafe(code = print(p))