user14176250
user14176250

Reputation: 55

chart alignment in plotly bar chart

my title alignment is not working left in chart. how to align title left.

I am trying to align title left in my graph below but not working for me please help what am i missing here or which line i have to update

df <- data.frame("LOC" =c("CA","NY","WA","TX"),
                 "TAX" = c(3421.00,5640.00,7880.32,4569.00))

ttl ="Tax collection"

g <- plot_ly(df, x =~TAX, y = ~ LOC, type = 'bar',width = 1200, height =900, showlegend=F
             , text = ~paste0(roundUp(TAX*100), "%"), textposition = "outside",
             marker = list(color = "blue"))


tit <- list(
  text = ttl,
  font = cht_ttl,
  xref = "paper",
  yref = "paper",
  xanchor = "right",
  x = 0.1,
  y = 1,
  showarrow = FALSE
)
ax <- list(
  title = "",
  showgrid = FALSE,
  range = c(0, 1)
)

chart <- g %>% layout(annotations = tit,
                      xaxis = ax,
                      yaxis = list (title = " "),font=chrt_title, showline = TRUE)

chart

Upvotes: 0

Views: 1042

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389215

Use xanchor = 'left' with x value less than 0.

library(plotly)

tit <- list(
  text = ttl,
  font = chrt_title,
  xref = "paper",
  yref = "paper",
  xanchor = "left",
  x = -0.04,
  y = 1,
  showarrow = FALSE
)


chart <- g %>% layout(annotations = tit,
                      xaxis = ax,
                      yaxis = list (title = " "),
                      font=chrt_title, showline = TRUE)

chart

enter image description here

Upvotes: 0

Related Questions