Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

R Plotly: How to change position of tick text in horizontally oriented reversed bar chart?

$
0
0

I have a bar chart that is horizontally oriented and it's flipped (autorange = 'reversed') so its base is on the right side. My problem is that ticktexts for Y-axis stay on the left side, where the Y-axis had been before being flipped. That means ticktexts are not at the base of the chart bars, but at their ends.

How do I change their position and move them to the right?

Image of the chart result

library(plotly)

my_data <- data.frame(Value = c(3, 6, 7, 4, 9), Type = c("Red", "Orange", "White", "Black", "Green"))

my_chart <- function(my_data){

  chart <-  plot_ly(my_data) %>% 
    plotly::add_trace(x = ~Value,   
                      y = ~Type, 
                      name = ~Type,
                      marker = list(color = "#4369ab"),
                      type = "bar",
                      orientation = 'h')

  chart %>% layout(yaxis = list(title = ""),
                 xaxis = list(title = "",
                              autorange = 'reversed'),
                 margin = list(pad = 6),
                 title = "",
                 showlegend = F)

}

my_chart(my_data)

Viewing all articles
Browse latest Browse all 201867

Trending Articles