For a sample dataframe:
df <- structure(list(year = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3,
3, 3, 4, 4, 4, 4, 4), imd.quintile = c(1, 2, 3, 4, 5, 1, 2, 3,
4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5), average_antibiotic = c(1.17153515458827,
1.11592565388857, 1.09288449967773, 1.07442652168281, 1.06102887394413,
1.0560582933182, 1.00678980505929, 0.992997489072538, 0.978343676071694,
0.967900478870214, 1.02854157116164, 0.98339099101476, 0.981198852494798,
0.971392872980818, 0.962289579742817, 1.00601488964457, 0.951187417739673,
0.950706064156994, 0.939174499710836, 0.934948233015044)), .Names = c("year",
"imd.quintile", "average_antibiotic"), row.names = c(NA, -20L
), vars = "year", drop = TRUE, class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
I am producing a graph detailing the differences in antibiotic prescribing BY imd.decile BY year:
ggplot(plot_data.quintiles) +
geom_col(aes(x = year, y = average_antibiotic, group=imd.quintile, fill=imd.quintile), position = "dodge") +
ylab("Antibiotic STAR-PU") +
xlab("Year") +
theme_bw() +
ylim(0, 1.5)+
scale_colour_brewer("clarity")
The blue colour choice isn't to my taste, as the differences between the imd.quintiles isn't very distinctive. I have read various posts, here, here and here, but none of which seem to answer my question.
I attempted to use the 'clarity' colours to get a wider range of colour choices. How can I correctly change the fill colour in my ggplot2 graph? what options do I have?
scale_####_brewer
uses palettes fromRColorBrewer
, there's no palette called "Clarity".Use
RColorBrewer::display.brewer.all()
to see what palette's are available, then call them by name with thepalette
arg. Also you need to change theimd.quintile
variable to be either character or factor. You're mapping your aesthetics by fill also, not colour, so you need to usescale_fill_brewer
.Is this what you want? Use
factor(imd.quintile)
to create discrete (categorical) data otherwiseggplot
will treat numeric/integerimd.quintile
as continuous.If you prefer continuous (sequential) colormaps, viridis or scico are good options:
Created on 2018-11-29 by the reprex package (v0.2.1.9000)