- Related Questions & Answers
- 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?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- Count sub-arrays which have elements less than or equal to X in C++
- How to create a subset of matrix in R using greater than or less than a certain value of a column?
- How to represent all values of X-axis or Y-axis on the graph in R using ggplot2 package?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- Print triplets with sum less than or equal to k in C Program
- Count elements such that there are exactly X elements with values greater than or equal to X in C++
- How to change ordinal X-axis label to text labels using ggplot2 in R?
- How to get the largest integer less than or equal to a number in JavaScript?
- Find all factorial numbers less than or equal to n in C++
- Print all prime numbers less than or equal to N in C++
- How to X-axis labels to the top of the plot using ggplot2 in R?
- How to get the smallest integer greater than or equal to a number in JavaScript?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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)))

Advertisements