I need to add data labels with % signs to my dumbbell plot. Any idea how to do this? I have code that attempts to do this, but get the error "Error in x * 100 : non-numeric argument to binary operator". Also is it possible to increase the font of the statements on the graph? See my code below, and data and graph here
data: https://gofile.io/d/k8vadK graph: https://i.stack.imgur.com/2SExW.jpg
blue <- "#0171CE"
red <- "#DE4433"
percent_first <- function(x) {
x <- sprintf("%d%%", round(x*100))
x[2:length(x)] <- sub("%$", "", x[2:length(x)])
x
}
library(ggplot2)
library(ggalt)
library(tidyverse)
ggplot() +
geom_segment(data=overall, aes(y=statement, yend=statement, x=0.8, xend=1), color="#b2b2b2", size=0.15) +
geom_dumbbell(data=overall, aes(y=statement, x=prior, xend=current),
size=1.5, color="#b2b2b2", size_x=3, size_xend = 3, colour_x = red, colour_xend = blue) +
geom_text(data=filter(overall, statement=="The meeting was well organized"),
aes(x=current, y=statement, label="2020"),
color=blue, size=3, vjust=-1.5, fontface="bold", family="Arial") +
geom_text(data=filter(overall, statement=="The meeting was well organized" ),
aes(x=prior, y=statement, label="2019"),
color=red, size=3, vjust=-1.5, fontface="bold", family="Arial") +
geom_text(data=overall, aes(x=prior, y=statement, label=percent_first(rep)),
color=red, size=2.75, vjust=2.5, family="Arial") +
geom_text(data=overall, color=blue, size=2.75, vjust=2.5, family="Arial",
aes(x=prior, y=statement, label=percent_first(dem)))