# 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_continuous_diverging()
# plot with alternative scale
gg + scale_fill_continuous_diverging(palette = "Purple-Green")
# plot with modified alternative scale
gg + scale_fill_continuous_diverging(palette = "Blue-Red 3", l1 = 30, l2 = 100, p1 = .9, p2 = 1.2)
# }
Run the code above in your browser using DataLab