- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 create bar plot with log values using ggplot2 in R?
To create the bar plot using ggplot2, we simply need to use geom_bar function and if we want to have the log scale of y variable then it can be set with aes under geom_bar. For example, if we have a data frame called df that contains a categorical column x and a numerical column y then the bar plot with log of y can be created by using the below command −
ggplot(df,aes(x,y))+geom_bar(stat="identity",aes(y=log(y)))
Example
Consider the below data frame −
> x<-c("S1","S2","S3","S4") > y<-sample(10000:99999,4) > df<-data.frame(x,y) > df
Output
x y 1 S1 53347 2 S2 84208 3 S3 12140 4 S4 59105
Loading ggplot2 package and creating bar chart for data in df −
> library(ggplot2) > ggplot(df,aes(x,y))+geom_bar(stat="identity")
Output
Creating bar chart for data in df with log of y −
> ggplot(df,aes(x,y))+geom_bar(stat="identity",aes(y=log(y)))
Output
- Related Articles
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create transparent bar plot using ggplot2 in R?
- How to create bar plot with gradient colors using ggplot2 in R?\n
- How to create a bar plot using ggplot2 with one bar having black border in R?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- How to create bar plot using ggplot2 with structure data frame?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- How to change legend values in a bar plot created by using ggplot2 in R?
- How to change the Y-axis values in a bar plot using ggplot2 in R?
- How to create stacked plot with density using ggplot2 in R?
- How to create bar plot with positive and negative values in R?
- How to create a bar plot with bars for missing values in R?
- How to create bar chart using ggplot2 with chart sub-title in R?

Advertisements