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, 2019 in Data Analytics by manikandan
3,675 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, 2019 by anonymous
• 33,030 points

Related Questions In Data Analytics

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,790 points
4,019 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,840 points
18,774 views
0 votes
1 answer
0 votes
1 answer

How to change y axis max in time series using R?

The axis limits are being set using ...READ MORE

answered Apr 3, 2018 in Data Analytics by Sahiti
• 6,370 points
3,530 views
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

edited Jun 9, 2020 by MD 8,525 views
+1 vote
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,090 points
24,702 views
0 votes
11 answers

Changing the legend title in ggplot

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

answered Jul 30, 2019 in Data Analytics by Cherukuri
• 33,030 points
16,964 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,240 points
915 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, 2019 in Data Analytics by sindhu
2,550 views
+1 vote
2 answers

change the color for bars in geom_bar in ggplot

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

answered Jul 24, 2019 in Data Analytics by Cherukuri
• 33,030 points
34,954 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP