如何更改x轴的字体以及如何加粗

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

谁能告诉我怎么改x轴的字体,也告诉我怎么加粗

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')

您可以使用 family 参数更改字体。 titleticks 有不同的参数,您可以根据要更改的部分更改两个参数。

没有关于粗体或斜体的参数,因此您可能需要一个解决方法。 ticktext(HTML 以粗体显示 set word between)将覆盖 textvals 中的文本。使用 categoryarray 您可以定义 x 类别的顺序。

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',
         xaxis = list(#axis title
                      title = "<b>Animals</b>",
                      titlefont = list(family = "Times New Roman"),
                      #axis ticks - names
                      tickfont = list(family = "Times New Roman"),
                      ticktext = paste0("<b>", levels(factor(data$Animals)), "</b>"),
                      tickvals = levels(factor(data$Animals)),
                      #axis ticks - order
                      categoryorder = "array",
                      categoryarray = levels(factor(data$Animals))))