【问题标题】:How to change the font of x axis and also how to make bold如何更改x轴的字体以及如何使粗体
【发布时间】:2021-06-09 10:21:12
【问题描述】:

谁能告诉我如何更改 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')

【问题讨论】:

    标签: r plotly ggplotly


    【解决方案1】:

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

    粗体或斜体没有参数,因此您可能需要一种解决方法。 ticktext(HTML 用于在粗体之间设置单词)将覆盖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))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 2020-09-24
      • 2016-11-21
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 2014-07-16
      相关资源
      最近更新 更多