library(ggplot2) # Enable the installed ggplot2 package, a collection of plotting tools.
dat <- data.frame( # Begin a table with one row per group.
  group = c("A", "B", "C", "D"), # Put the four text group names in order.
  value = c(8, 11, 9, 14) # Put the four numeric values in the matching order.
) # Finish the table and save it as dat.
cols <- c( # Begin a group-to-color vector.
  A = "#2066B0", B = "#E18B32", # Assign blue to A and orange to B.
  C = "#5B9279", D = "#874EA1" # Assign green to C and purple to D.
) # Save the named color vector as cols.
p <- ggplot(dat, aes(x = group, y = value, fill = group)) + # Connect table columns to the plot; + adds the next plot component.
  geom_col(width = 0.40, colour = "#313743") + # Draw bar heights from value and give the bars a dark outline.
  scale_fill_manual(values = cols) + # Use group names to match bar fills with the chosen colors.
  labs(x = "Group", y = "Value") + # Name the horizontal and vertical axes.
  theme_minimal(base_size = 13, base_family = "Arial") + # Set a simple grid, a base text size of 13 points and Arial.
  theme(legend.position = "none") # Use the horizontal group labels to identify the colors.
ggsave("palette-example.png", plot = p, width = 160, height = 100, # Save plot p at 160 by 100 millimeters in the current folder.
       units = "mm", dpi = 180, device = grDevices::png, type = "cairo", bg = "white") # Write a PNG at 180 DPI with the Cairo device and a white background.
