
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display Long X-Axis Labels in Bar Chart Using Plotly in R
Plotly in R is a package specifically designed to create highly-interactive and publication-quality charts. The chart can be created by using plot_ly function of the package and there are three main arguments of plot_ly defined as x, y, and type, where x refers to the X-axis, y refers to the Y-axis and type refers to the chart type but the axes values are stored in a data frame or itself a shared.
Example
Loading plotly package:
> library(plotly)
Consider the below data frame:
> x<-c("United States of America","United Kingdom","Republic of China") > y<-c(501,510,505) > df<-data.frame(x,y) > df
Output
x y 1 United States of America 501 2 United Kingdom 510 3 Republic of China 505
Creating the bar plot for x:
Example
> plot_ly(x=x,y=y,type="bar")%>%layout(xaxis=list(tickangle=45))
Output
Warning message: `arrange_()` is deprecated as of dplyr 0.7.0. Please use `arrange()` instead. See vignette('programming') for more help This warning is displayed once every 8 hours. Call `lifecycle::last_warnings()` to see where this warning was generated.
Here it is showing a warning but it is not related to our chart hence there is no problem in ignoring it.
Output
Advertisements