Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

R Plotly - xaxis labels ever other tick, change to all

I am trying to get all the labels to appear on every tick on the x-axis, but as you can see in the picture below they printed everyone tick.

enter image description here

Here is the R plotly code I have.

    fig <- plot_ly(width = 1000 )
    fig <- fig %>% 
      add_bars(data=filter(mbt, ANIMAL == 'CAT'),
               x = ~as.Date(paste0("01-",TITLE),format = "%d-%b-%y"), y = ~count, type = 'bar', text = ~count,
               textposition = 'auto', marker = list(color = 'rgb(113,88,143)'), name = "Cat", yaxis = "y2")
    fig <- fig %>% 
      add_bars(data=filter(mbt, ANIMAL == 'DOG'),
               x = ~as.Date(paste0("01-",TITLE),format = "%d-%b-%y"), y = ~count, type = 'bar', text = ~count,
               textposition = 'auto',marker = list(color = 'rgb(65,152,175)'), name = "Dog",yaxis = "y2")
    fig <- fig %>%
      add_lines(data=filter(mbt, ANIMAL == 'CAT'),
                x = ~as.Date(paste0("01-",TITLE),format = "%d-%b-%y"),y=~percentage, line = list(color = 'rgb(113,88,143)'),name = "P - Cats", yaxis ="y")
    fig <- fig %>%
      add_lines(data=filter(mbt, ANIMAL == 'DOG'),
                x = ~as.Date(paste0("01-",TITLE),format = "%d-%b-%y"),y=~percentage,  line = list(color = 'rgb(65,152,175)'),name = "P - Dogs", yaxis ="y")
    fig <- fig %>%
      add_lines(data=filter(mbt, ANIMAL == 'Total'),
                x = ~as.Date(paste0("01-",TITLE),format = "%d-%b-%y"),y=~percentage,  line = list(color = 'rgb(255,0,0)'), name = "Total", yaxis ="y")
    fig <- fig %>%
      add_lines(data=mbt,
                x = ~as.Date(paste0("01-",TITLE),format = "%d-%b-%y"),y=~percent_target, name="Target",yaxis ="y",line = list(color = 'rgb(0, 0, 0)')) 
    fig <- fig %>%
      layout( barmode = 'stack',
              yaxis2 = list(title ="", side = "right", tickprefix="<b>",ticksuffix = "</b>", range=c(0,24000),dtick = 2000, tickformat = "digits",showgrid = FALSE, zeroline = FALSE),
              yaxis = list(title = "", tickformat= ".1f", tickprefix="<b>",ticksuffix = "%</b>", overlaying = "y2",side = 'left',range = c(97,100.01)),
              xaxis = list(title = "", tickmode = "array", tickvals = ~as.Date(paste0("01-",TITLE),format = "%d-%b-%y"), tickformat = "%b-%y",tickfont = list(size = 10), tickprefix="<b>",ticksuffix = "</b>"),
              legend = list(orientation = "h", xanchor="center", x = 0.5),
              margin = list(l = 20, r = 50, b = 10, t = 100),
              annotations=list(text="Cat/Dog",xref="paper",x=0.5,
                               yref="paper",y=1,yshift=100,showarrow=FALSE, 
                               font=list(size=26))) %>%
      config(displayModeBar = FALSE)
    
    fig

Any idea's on what I should try?

Thanks

question from:https://stackoverflow.com/questions/66057993/r-plotly-xaxis-labels-ever-other-tick-change-to-all

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to reply this article.

OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...