修改 R Plotly 中的单个刻度标签
假设我有一些代码,例如,
Suppose I have some code such as,
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')
我想弄清楚我是如何给三个 x 轴标签(长颈鹿、猴子、猩猩)涂上不同颜色的,我一直在尝试使用类似的东西来做到这一点,
I'm trying to figure out how I color the three x-axis labels (giraffes, monkeys, orangutans) different colors, I've been trying to do this by using something like,
xaxis=list(tickfont=list(color=c('red', 'yellow', 'blue')))
在 layout
函数中,但它不起作用.
inside the layout
function, but it doesn't work.
如何单独修改刻度标签?
How can I modify tick labels individually?
目前这并不像 xaxis=list(tickfont=list(color=c('red', 'yellow)', 'blue')))
因为刻度标签的颜色与轴的属性相关联,而不是单个刻度.您可以为可见轴的不同部分指定不同的颜色,但您必须添加额外的轴.这已在此处详细完成:为轴刻度着色多种颜色的文字
At the time being this isn't as straight forward as xaxis=list(tickfont=list(color=c('red', 'yellow', 'blue')))
since the color of the tick labels are associated with the properties of the axis and not the individual ticks. You can assign different colors to different parts of the visible axis, but you'll have to add extra axes. This has been done in detail here: Coloring the axis tick text by multiple colors