- 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 represent X-axis label of a bar plot with greater than equal to or less than equal to sign using ggplot2 in R?
The values of the categorical variable can be represented by numbers, by characters, by a combination of numbers and characters, by special characters, by numerical signs or any other method. But when we create the bar plot, if the size of a label name is large then we might want to reduce it by representing it with a different word or character or sign that gives the same meaning and it can be done by using expression argument inside scale_x_discrete.
Consider the below data frame −
> x<-c("0","100","150","200","Greater than 200") > y<-c(25,28,32,25,37) > df<-data.frame(x,y) > df
x y 1 0 25 2 100 28 3 150 32 4 200 25 5 Greater than 200 37
Creating the bar plot −
> library(ggplot2) > ggplot(df,aes(x,y))+geom_bar(stat="identity")
Now suppose, you want to replace “Greater than 200” with >=200 then it can be done as shown below −
> ggplot(df,aes(x,y))+geom_bar(stat="identity")+ + scale_x_discrete(labels=c("0","100","150","200",expression("">=200)))
- How to add approximately equal sign in a plot using ggplot2 in R?
- How to convert the X-axis label in a bar plot to italic using ggplot2 in R?
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Program to find X for special array with X elements greater than or equal X in Python
- Count sub-arrays which have elements less than or equal to X in C++
- How to find the frequency of values greater than or equal to a certain value in R?
- Print triplets with sum less than or equal to k in C Program
- How to create a subset of matrix in R using greater than or less than a certain value of a column?
- Find all factorial numbers less than or equal to n in C++
- Print all prime numbers less than or equal to N in C++
- Count elements such that there are exactly X elements with values greater than or equal to X in C++
- Maximum Side Length of a Square with Sum Less than or Equal to Threshold in C++
- Mask array elements greater than or equal to a given value in Numpy