# NOT RUN {
library("ggplot2")
# volcano plot (difference from mean height)
nx = 87
ny = 61
df <- data.frame(diff = c(volcano) - mean(volcano), x = rep(1:nx, ny), y = rep(1:ny, each = nx))
ggplot(df, aes(x, y, fill=diff)) +
geom_raster() + scale_fill_binned_divergingx(palette = "Fall", rev = TRUE) +
coord_fixed(expand = FALSE)
# adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218
# 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 diverging scale "Geyser"
gg + scale_fill_binned_divergingx(palette = "Geyser", n.breaks = 6)
# }
Run the code above in your browser using DataCamp Workspace