Change ggplot2 default color palette

0 votes
I want to customize the chart color and fill colors, how to change them for ggplots?
Aug 1 in Data Analytics by manikandan
21 views

1 answer to this question.

0 votes

If the scale is continuous, then you can change the default palette using scale_fill/color_continuous

# default
ggplot(mpg,aes(cyl,displ))+geom_bar(stat="identity")
ggplot(mpg,aes(cyl,displ,fill = cyl))+geom_bar(stat="identity")
# color palette - Viridis
ggplot(mpg,aes(cyl,displ,fill = cyl))+geom_bar(stat="identity")+scale_fill_continuous(type = "viridis")
# Assign color to pallete manually
ggplot(mpg,aes(cyl,displ,fill = cyl))+geom_bar(stat="identity")+scale_fill_gradient(low = "red",high = "green")

If the scale is discrete, then you can provide the colors using 

# default

ggplot(mpg[1:20,],aes(x=model))+geom_point(stat="count")

ggplot(mpg[1:20,],aes(x=model,color = model))+geom_point(stat="count")

# ColorBrewer - palette options/color.

ggplot(mpg[1:20,],aes(x=model,color = model))+geom_point(stat="count")+scale_color/fill_brewer(palette = "Set1")

Hope it helps!

answered Aug 20 by anonymous
• 27,960 points

Related Questions In Data Analytics

0 votes
0 answers

ggplot2 - assign color palette to legend

How to edit the legend color in ...READ MORE

Aug 1 in Data Analytics by vishal
11 views
0 votes
1 answer

How can I change font size and direction of axes text in ggplot2 ?

You can try theme(): Library(ggplot2) a <- data.frame(x=gl(10, 1, ...READ MORE

answered May 30, 2018 in Data Analytics by zombie
• 3,690 points
548 views
0 votes
1 answer

How do I change background color in Rstudio

Follow this: tools > global options > appearance ...READ MORE

answered Nov 2, 2018 in Data Analytics by Maverick
• 10,040 points
57 views
0 votes
1 answer
0 votes
1 answer

How to plot side-by-side Plots with ggplot2 in R?

By Using gridExtra library we can easily ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,563 views
0 votes
1 answer

How to change fill color in each facet using ggplot2?

You can map the facetting variable to ...READ MORE

answered May 8, 2018 in Data Analytics by kappa3010
• 2,020 points
2,878 views
0 votes
11 answers

Changing the legend title in ggplot

Hi, you can also try guides() to ...READ MORE

answered Jul 30 in Data Analytics by Cherukuri
• 27,960 points
5,821 views
0 votes
1 answer

How to order bars in a bar graph using ggplot2?

The key to ordering is to set ...READ MORE

answered Jun 1, 2018 in Data Analytics by DataKing99
• 8,130 points
174 views
0 votes
2 answers

Change the default order of labels of factor in R

You can also use relevel() to change ...READ MORE

answered Jun 27 in Data Analytics by sindhu
35 views
0 votes
1 answer

change the color for bars in geom_bar in ggplot

Hi @radha, You can have 2 types of ...READ MORE

answered Jul 24 in Data Analytics by Cherukuri
• 27,960 points
150 views