问题
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')
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')))
inside the layout
function, but it doesn't work.
How can I modify tick labels individually?
回答1:
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
来源:https://stackoverflow.com/questions/59061655/modifying-individual-tick-labels-in-r-plotly