我想知道如何把第二张图片的颜色换成第一张。我刚接触ggplot2,还在学自动取款机。
library(tidyverse)
data(mpg)
ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = clarity),
position = "dodge"
)我以为我第一张照片会有很多颜色,但第二张照片我得到了颜色。First pic Second pic
发布于 2021-06-19 00:06:49
您可以使用各种方法更改颜色。这里有几个例子:
通过使用scale_fill_manual和
ggplot(diamonds, aes(cut))+
geom_bar(position = "dodge", aes(fill = clarity))+
scale_fill_manual(values = c("#0CFCA0", "#A54408", "#E53975", "#7FB0FF",
"#4ACC0A", "#51397F", "#FFC059", "#062C7F"))它创建了这个:Manual colours - excuse the choices, they were at random
This page有你在第一张图片中展示的ggplot2默认颜色的代码。
作为上面提到的maarvd,你可以使用RColorBrewer
ggplot(diamonds, aes(cut))+
geom_bar(position = "dodge", aes(fill = clarity))+
scale_fill_brewer(palette = "RdYlBu")它创建了这个:Brewer colours
https://stackoverflow.com/questions/68036437
复制相似问题