- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 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.
Example
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
Output
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")
Output
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)))
- Related Articles
- How to convert the X-axis label in a bar plot to italic using ggplot2 in R?
- How to add approximately equal sign in a plot using ggplot2 in R?
- Complete the following statements:The probability of an event is greater than or equal to …………. and less than or equal to ………..
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Linear magnification produced by a concave mirror may be:(a) less than 1 or equal to 1 (b) more than 1 or equal to 1(c) less than 1, more than 1 or equal to 1 (d) less than 1 or more than 1
- Linear magnification produced by a convex lens can be:(a) less than 1 or more than 1.(b) less than 1 or equal to 1.(c) more than 1 or equal to 1.(d) less than 1, equal to 1 or more than 1.
- How to find the frequency of values greater than or equal to a certain value in R?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- Program to find X for special array with X elements greater than or equal X in Python
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- An angle is greater than $45^{circ}$. Is its complementary angle greater than $45^{circ}$ or equal to $45^{circ}$ or less than $45^{circ}$?
- How to create a plot using ggplot2 by including values greater than a certain value in R?
- How to create a subset of matrix in R using greater than or less than a certain value of a column?
- How to change the color of X-axis label using ggplot2 in R?
- Count sub-arrays which have elements less than or equal to X in C++

Advertisements