- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the bars color to grey shade of a bar graph created by using ggplot2 in R?
When we create a bar graph using ggplot2, the color of the bars is dark grey but it can be changed to different colors or we can also give different shades of grey to them. This will be helpful if we are plotting a pattern of categorical data. For example, plotting educational level on X-axis with frequencies of years of experience on Y-axis. We can do this by using scale_fill_grey function of ggplot2 package.
Consider the below data frame −
> x<-c("A","B","C","D") > Freq<-c(14,12,13,15) > df<-data.frame(x,Freq) > df
x Freq 1 A 14 2 B 12 3 C 13 4 D 15
> library(ggplot2) > ggplot(df,aes(x,Freq))+geom_bar(stat="identity")
Giving grey shades to bars −
> ggplot(df,aes(x,Freq))+geom_bar(stat="identity",aes(fill=x))+scale_fill_grey(start=0,end =0.8)
- Related Articles
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to change the thickness of the borders of bars in bar plot created by using ggplot2 in R?
- How to change legend values in a bar plot created by using ggplot2 in R?
- Change the starting point of bars in bar plot for a ggplot2 graph in R.
- Change the outline color for histogram bars using ggplot2 in R.
- How to change the color of gridlines of a ggplot2 graph in R?
- How to change the plot border color of a ggplot2 graph in R?
- How to reverse the bars of a bar plot a using ggplot2 in R?
- How to align the text horizontally in a bar plot created by using ggplot2 in R?
- How to change the size of dots in dotplot created by using ggplot2 in R?
- How to change the border color of points in a scatterplot created with ggplot2 in R?
- How to fill bars of a bar plot created using ggplot2 with colors based on frequency?
- How to increase the space between bars of a bar plot using ggplot2 in R?
- How to create a horizontal bar graph using ggplot2 in R?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?