I want to create in R a graphic similar to the one below to show where a certain person or company ranks relative to its peers. The score will always be between 1 and 100.
Although I am amenable to any ggplot
solution it seemed to me that the best way would be to use geom_rect
and then to adapt and add the arrowhead described in baptiste's answer to this question. However, I came unstuck on something even simpler - getting the geom_rect
to fill properly with a gradient like that shown in the guide to the right of the plot below. This should be easy. What am I doing wrong?
library(ggplot2)
library(scales)
mydf <- data.frame(id = rep(1, 100), sales = 1:100)
ggplot(mydf) +
geom_rect(aes(xmin = 1, xmax = 1.5, ymin = 0, ymax = 100, fill = sales)) +
scale_x_discrete(breaks = 0:2, labels = 0:2) +
scale_fill_gradient2(low = 'blue', mid = 'white', high = 'red', midpoint = 50) +
theme_minimal()