在"R闪亮"而不是“底部"中的绘图图的顶部显示X轴? [英] Display X Axis at Top of Plotly Plot in R Shiny Instead of Bottom?

查看:67
本文介绍了在"R闪亮"而不是“底部"中的绘图图的顶部显示X轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将x轴显示在Plotly水平条形图的顶部而不是底部?在顶部和底部同时显示x轴也可以.该图将以"R闪亮"显示,并且必须是绘图"而不是"ggplotly".谢谢!

How do I display the x axis at the top of a Plotly horizontal bar plot instead of at the bottom? Showing the x axis at both the top and bottom would also be ok. The plot will be displayed in R Shiny and must be Plotly not ggplotly. Thanks!

https://plot.ly/r/horizo​​ntal-bar-charts/:

library(plotly)
plot_ly(x = c(20, 14, 23), 
y = c('giraffes', 'orangutans', 'monkeys'), 
type = 'bar', 
orientation = 'h')

HubertL提供了一个解决方案(谢谢!),该解决方案将x轴放在顶部,但随后与图表标题重叠.我没有指定我使用标题的过错.有没有一种方法可以使x轴标题和x轴刻度线不与绘图标题重叠?

HubertL provided a solution (thanks!) that puts the x axis at the top but it then overlaps with the chart title. My fault for not specifying that I am using a title. Is there a way to get the x axis title and x axis ticks to not overlap the plot title?

plot_ly(x = c(20, 14, 23), 
        y = c('giraffes', 'orangutans', 'monkeys'), 
        type = 'bar', 
        orientation = 'h') %>%
   layout(xaxis = list(side ="top", 
          title = "EXAMPLE X AXIS TITLE"), 
          title = "EXAMPLE PLOT TITLE")

推荐答案

您可以在layout.xaxis

plot_ly(x = c(20, 14, 23), 
        y = c('giraffes', 'orangutans', 'monkeys'), 
        type = 'bar', 
        orientation = 'h') %>%
  layout(xaxis = list(side ="top" ) ) 

这篇关于在"R闪亮"而不是“底部"中的绘图图的顶部显示X轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆