- 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 plotly bar chart with values on top of bars in R?
To create plotly bar chart with values on top of bars in R, we can follow the below steps −
- First of all, create two vectors one having categories and one counts and create the bar chart using plotly.
- Then, create the same bar chart with add_text function of plotly package.
Create the vectors and plotly bar chart
Using c function to create the vectors and plotly function with layout function to create the bar chart with axes titles −
x<-c("A","B","C") freq<-c(48,40,42) library(plotly) plot_ly(x=x,y=freq,type="bar")%>%layout(xaxis=list(title="X"),yaxis=list(title="Y"))
Output
Create the bar chart with counts on top of the bars
Using add_text function to create the bar chart with counts on top of the bars −
x<-c("A","B","C") freq<-c(48,40,42) library(plotly) plot_ly(x=x,y=freq,type="bar")%>%layout(xaxis=list(title="X"),yaxis=list(title="Y"))% >%add_text(x=x,y=freq,text=freq,textposition="top")
Output
- Related Articles
- How to create plotly bar chart with negative values in R?
- How to decrease the width of bars for plotly bar chart in R?
- How to create a bar chart using plotly in R?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to create a bar chart using ggplot2 with dots drawn at the center of top edge of the bars in R?
- How to create a bar plot with bars for missing values in R?
- How to create pie chart using plotly in R?
- How to change the order of bars in bar chart in R?
- How to create a horizontal bar chart using ggplot2 with labels at inside end of the bars in R?
- How to create bar chart using ggplot2 with chart sub-title in R?
- How to display long X-axis labels in a bar chart using plotly in R?
- Create stacked bar chart with percentages on Y-axis using ggplot2 in R.
- Annotate bars with values on Pandas bar plots in Python
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to create stacked bar chart using ggvis in R?

Advertisements