How to remove numbers between log scales in plotly function?

Viewed 715

I'm trying to remove the numbers between log scales in plot made using plot_ly in r. Follows the graph:

enter image description here

I need ticks on the x-axis only at 1, 2, and 3 and on the y-axis only at 100 and 10k. How can I achieve this?

Here is my code:

library(plotly) 

d <- diamonds[sample(nrow(diamonds), 1000), ] 

fig <- plot_ly(d, x = ~carat, y = ~price) %>% add_markers() 

fig <- layout(fig, xaxis = list(type = "log"), yaxis = list(type = "log"))

fig
1 Answers

You can use dtick in your layout:

With axis type "log", ticks are set every 10^(n dtick) where n is tick number. Set dtick to 1 for ticks at 10,100,1000,10000,etc. (appropriate for y axis).

For linearly spaced in value (but not position) use "L[f]" where f is a positive number. "L1" gives ticks at 1,2,3,etc. (appropriate for x axis).

Reference: https://plotly.com/r/reference/#layout-xaxis-dtick

library(plotly) 

d <- diamonds[sample(nrow(diamonds), 1000), ] 

fig <- plot_ly(d, x = ~carat, y = ~price) %>% add_markers() 

fig <- layout(fig, 
              xaxis = list(type = "log", dtick = "L1"), 
              yaxis = list(type = "log", dtick = 1)
)

fig

Plot

enter image description here

Related