- 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 negative values in R?
To create plotly bar chart with negative values in R, we can follow the below steps −
- First of all, create a data frame.
- Then, create the bar chart using plotly with horizontal orientation.
Create the data frame
Let's create a data frame as shown below −
Group<-c("A","B") Score<-c(-10,5) df<-data.frame(Group,Score) df
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Group Score 1 A -10 2 B 5
Create the bar chart with horizontal orientation
Using plot_ly function with Group.orientation for y values set to "h" to create the bar chart −
Group<-c("A","B") Score<-c(-10,5) df<-data.frame(Group,Score) library(plotly) plot_ly(df,type="bar",x=Score,y=Group,orientation="h")
Output
- Related Articles
- How to create plotly bar chart with values on top of bars in R?
- How to create a bar chart using plotly in R?
- How to create bar plot with positive and negative values in R?
- How to create pie chart using plotly in R?
- How to create bar chart using ggplot2 with chart sub-title in R?
- How to decrease the width of bars for plotly bar chart in R?
- JavaFX example to create area chart with negative values
- How to display long X-axis labels in a bar chart using plotly in R?
- How to create stacked bar chart using ggvis in R?
- How to create the bar chart with ggplot2 using color brewer in R?
- How to create horizontal stacked bar chart using ggvis in R?
- How to create bar plot with log values using ggplot2 in R?
- How to create varying width bar chart using barplot function in R?
- How to create a bar plot with bars for missing values in R?
- How to create a bar chart for single vector using ggplot2 in R?

Advertisements