Search code examples
rplotlyggplotly

How to change the font of x axis and also how to make bold


Can anyone tell me how to change the font of x axis and also tell me how to make bold

library(plotly)
    Animals <- c("giraffes", "orangutans", "monkeys")
    SF_Zoo <- c(20, 14, 23)
    LA_Zoo <- c(12, 18, 29)
    data <- data.frame(Animals, SF_Zoo, LA_Zoo)
    p <- plot_ly(data, x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF Zoo') %>%
      add_trace(y = ~LA_Zoo, name = 'LA Zoo') %>%
      layout(yaxis = list(title = 'Count'), barmode = 'stack')

Solution

  • You can use the titlefont family "Arial black" as in python.

    library(plotly)
    Animals <- c("giraffes", "orangutans", "monkeys")
    SF_Zoo <- c(20, 14, 23)
    LA_Zoo <- c(12, 18, 29)
    p <- plot_ly(x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF Zoo') %>%
      add_trace(y = ~LA_Zoo, name = 'LA Zoo') %>%
      layout(yaxis = list(title = 'Count', titlefont = list(family = "Arial black"), tickfont = list(family = "Arial black")), 
             xaxis = list(title = 'Animals', titlefont = list(family = "Arial black"), tickfont = list(family = "Arial black")),
             barmode = 'stack')