Modifying individual tick labels in R Plotly

╄→尐↘猪︶ㄣ 提交于 2020-01-16 04:28:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!