谁能告诉我如何改变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))))
您可以像在 python 中一样使用 titlefont 系列“Arial black”。
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')