有人能告诉我如何更改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
参数更改字体。title
和ticks
有不同的参数,您可以根据要更改的部分更改这两个参数。
粗体或斜体没有任何争议,因此您可能需要一个变通方法。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))))