我想知道如何将第二张图片的颜色更改为第一张我是 ggplot2 的新手并且仍在学习 atm
library(tidyverse)
data(mpg)
ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = clarity),
position = "dodge"
)
You can change the colour using various methods. Here are a couple of examples:
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"))
Which creates this: Manual colours - excuse the choices, they were at random
This page has the codes from the ggplot2
default colours you showed in yout first picture.
RColorBrewer
ggplot(diamonds, aes(cut))+
geom_bar(position = "dodge", aes(fill = clarity))+
scale_fill_brewer(palette = "RdYlBu")
Which creates this: Brewer colours