# NOT RUN {
# adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218
library("ggplot2")
# generate dataset and base plot
set.seed(100)
df <- data.frame(country = LETTERS, V = runif(26, -40, 40))
df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors
gg <- ggplot(df, aes(x = country, y = V, fill = V)) +
geom_bar(stat = "identity") +
labs(y = "Under/over valuation in %", x = "Country") +
coord_flip() + theme_minimal()
# plot with default diverging scale
gg + scale_fill_binned_diverging(n.breaks = 6)
# plot with alternative scale
gg + scale_fill_binned_diverging(palette = "Purple-Green", n.breaks = 6)
# }
Run the code above in your browser using DataLab