如何在 R 中使用 plotly 在条形图中显示长 X 轴标签?
在 R 中的 Plotly 是一个专为创建高度交互式且具有出版物质量的图表而设计的包。可以通过使用包的 plot_ly 函数创建图表,并且 plot_ly 的三个主要参数定义为 x、y 和 type,其中 x 指 X 轴,y 指 Y 轴,type 指图表类型,但是轴值存储在数据帧中,或者其本身是共享的。
示例
加载 plotly 包
> library(plotly)
考虑以下数据帧
> x<-c("United States of America","United Kingdom","Republic of China")
> y<-c(501,510,505)
> df<-data.frame(x,y)
> df输出
x y 1 United States of America 501 2 United Kingdom 510 3 Republic of China 505
为 x 创建条形图
示例
> plot_ly(x=x,y=y,type="bar")%>%layout(xaxis=list(tickangle=45))
输出
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.这里显示了警告,但它与我们的图表无关,因此忽略它没有问题。
输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP