Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

Please log in or register to answer this question.

Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...