library(ggplot2)
library(dplyr) # when filter(), mutate(), count(), arrange() etc. needed
library(readr) # when read_csv() needed
library(readxl) # when read_xls() or read_xlsx() needed
library(lubridate) # when make_date() or make_datetime() needed
<data> <- read_csv("<file>.csv") # or read_xlsx("<file>.xls", sheet = "<sheet>", ...)
<data> |> # required
filter(<condition>) |>
mutate(<varname> = <expression>) |> # optional data manipulation
count(<varname>) |>
arrange(<varname>) |>
ggplot(aes(<aesthetic> = <varname>, <aesthetic> = <varname>, ...)) + # required
histogram
density
boxplot
bar
point
line
geom_path(...) + # required
jitter
count
smooth
col
qq
qq_line
geom_*(...) + # optional additional geoms
labs(<aesthetic> = "<label>", <aesthetic> = "<label>", ...) + # required
grey
brewer
fermenter
distiller
color viridis_b
scale_colour_viridis_c(...) + # recommended, non-exhaustive list here
fill viridis_d
steps
steps2
gradient
gradient2
manual
scale_<aesthetic>_<scalename>(...) + ... + # optional additional scales
discrete
scale_x_continuous(...) + # optional
y log10
date
coord_cartesian(xlim = c(...), ylim = c(...)) + # recommended
stat_summary(fun = ...) + # optional
facet_grid(<varname> ~ <varname>) + # optional
wrap(~ <varname>)
grey
bw
theme_classic(base_size = ...) + # optional
minimal
void
theme(legend.position = "...") # optional
Notes on the placeholders:
<aesthetic> is the name of a ggplot2 aesthetic without quotes. Common aesthetics are: x, y, colour, fill, size, shape, linetype, alpha.<varname> is the name of a column in <data> without quotes.<label> (in labs()) is a human-readable string with quotes, e.g., "Engine Displacement (L)".library(ggplot2)
library(dplyr) # for optional data manipulations
library(sf) # for read_sf() & other manipulations with geospatial data
library(rnaturalearth) # for background map data
<data> <-
read_sf("<file>.shp") |> # required
... # optional data manipulation using dplyr functions
<map> <-
ne_countries(scale = "medium", country = "<country name>", returnclass = "sf")
ggplot() +
geom_sf(data = <map>) + # recommended
geom_sf(aes(<aesthetic> = <varname>, ...), data = <data>) + # required
labs(<aesthetic> = "<label>", ...) + # optional
grey
brewer
fermenter
distiller
color viridis_b
scale_colour_viridis_c(...) + # recommended, non-exhaustive list here
fill viridis_d
steps
steps2
gradient
gradient2
manual
scale_<aesthetic>_<scalename>(...) + ... + # optional additional scales
theme_void(base_size = ...) + # optional
theme(legend.position = "...") # optional
Notes:
x and y are usually not needed as aesthetics in geom_sf(). If POINT is the geometry type in the data, colour and size are the likely aesthetics. If POLYGON or MULTIPOLYGON is the geometry type, fill is the likely aesthetic.fill is used to map a variable, it might be useful to set colour to NA i.e.... + geom_sf(aes(fill = <varname>, ...), data = <data>, colour = NA) + ...