Skip to content

Instantly share code, notes, and snippets.

@ito4303
Last active October 22, 2021 13:02
Show Gist options
  • Save ito4303/d80a897aa702593a24245e21cdb1f3ac to your computer and use it in GitHub Desktop.
Save ito4303/d80a897aa702593a24245e21cdb1f3ac to your computer and use it in GitHub Desktop.
ggplot2 and color model
library(ggplot2)
# http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
# The palette with grey:
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")
data(iris)
p <- ggplot(iris) +
geom_histogram(aes(Sepal.Length, fill = Species),
binwidth = 0.5) +
scale_fill_manual(values = cbPalette)
ggsave("ggsave.pdf", plot = p, device = "pdf",
width = 12, height = 8, units = "cm")
pdf("ggplot-grey.pdf", width = 12 / 2.54, height = 8 / 2.54,
colormodel = "grey")
print(p)
dev.off()
pdf("ggplot-cmyk.pdf", width = 12 / 2.54, height = 8 / 2.54,
colormodel = "cmyk")
print(p)
dev.off()
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment