- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 display negative labels below bars in barplot using ggplot2 in R?
Be default, the labels on the plot are represented without sign in a barplot that is created by using ggplot2 but we might want to display the sign of the labels especially in cases where we have some negative values. This can be done with the help of geom_text function of ggplot2 package as shown in the below example.
Consider the below data frame −
x<-c("A","B","C","D") y<-c(21,-5,-20,10) df<-data.frame(x,y) df
x y 1 A 21 2 B -5 3 C -20 4 D 10
Loading ggplot2 package and creating bar chart for data in df −
Creating bar chart for data in df with negative labels displayed with negative sign −
- How to display zero frequency for bars in base R barplot?
- How to align the bars of a barplot with the X-axis using ggplot2 in R?
- How to display positive sign for X-axis labels in R using ggplot2?
- How to display axes ticks and labels inside the plot using ggplot2 in R?
- How to create colored barplot using ggplot2 without legend entries in R?
- How to change the color of bars in base R barplot?
- How to change the space between bars in a barplot in R?
- How to create stacked barplot using barplot function in R?
- How to create a horizontal bar chart using ggplot2 with labels at inside end of the bars in R?
- How to fill histogram bars using ggplot2 in R with different colors?
- How to display two equal signs in R using ggplot2?
- How to display legend on top using ggplot2 in R?
- R Programming how to display both axes’ labels of a ggplot2 graph in italics?
- How to extract axes labels for the plot drawn using ggplot2 in R?
- How to increase the X-axis labels font size using ggplot2 in R?