Le langage R dessine l'histogramme de quatre combinaisons de palettes de couleurs

library(ggplot2)

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "YlOrRd")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "YlOrBr")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "YlGnBu")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "YlGn")

# 构造ggplot图片列表
plots <- list(p1, p2, p3, p4)
# 自定义图片布局
gridExtra::grid.arrange(grobs = plots, ncol = 2)

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Reds")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "RdPu")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Purples")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuRd")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuBuGn")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuBu")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "OrRd")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Oranges")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Greys")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Greens")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "GnBu")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "BuPu")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "BuGn")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Blues")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Set1")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Set2")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Paired")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Dark2")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "RdYlBu")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "RdBu")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuOr")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PRGn")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PiYG")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "BrBG")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "YlOrRd")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "YlOrBr")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Set1")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Set2")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "ylGnBu")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "YlGn")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Set3")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Dark2")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Reds")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "RdPu")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Paired")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "RdYlBu")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "Purples")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuRd")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuOr")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PRGn")

insérez la description de l'image ici

# 普通的直方图
p1 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = cut)) + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuBuGn")

# 堆积直方图
p2 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "identity") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PuBu")

# 累积直方图
p3 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "PiYG")

# 分类直方图
p4 <- ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge") + 
  theme_linedraw() +
  scale_fill_brewer(palette = "BrBG")

insérez la description de l'image ici
Références : https://blog.csdn.net/weixin_46587777/article/details/124973766
Outils de développement : RStudio 2023.06.1 Build 524
WeChat Alt+A screenshot tool

Je suppose que tu aimes

Origine blog.csdn.net/m0_38127487/article/details/131778681
conseillé
Classement