问题
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!
Example from https://plot.ly/r/horizontal-bar-charts/:
library(plotly)
plot_ly(x = c(20, 14, 23),
y = c('giraffes', 'orangutans', 'monkeys'),
type = 'bar',
orientation = 'h')
EDIT: 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")
回答1:
You can use side ="top" in the layout.xaxis
plot_ly(x = c(20, 14, 23),
y = c('giraffes', 'orangutans', 'monkeys'),
type = 'bar',
orientation = 'h') %>%
layout(xaxis = list(side ="top" ) )
来源:https://stackoverflow.com/questions/44034368/display-x-axis-at-top-of-plotly-plot-in-r-shiny-instead-of-bottom