R Plotly 隐藏了 X 轴

R Plotly has X-axis hidden

当我绘制 r-plotly 图表时,它的 x 轴被隐藏了。下面是有这个问题的图表:

下面是我的代码:

p <- plot_ly(b1image, x = b1image$CNT, y = b1image$Label, type = 'bar', orientation = 'h', 
             marker = list(color = viridis::viridis_pal(option = "C", direction =1)(max(b1image$Label) - min(b1image$Label) + 5))) %>% 
  config(displayModeBar = F)
p

我想知道是否有办法避免隐藏 x 轴?

另外,我想知道如何改变y轴的比例。

例如,我不想在 y 轴上看到 5.5、4.5 ...,而只想看到 5、4、3 ...等。

提前致谢。

可以通过参数 showline = T 或在某些情况下使用 zeroline = T 取决于您的图是否实际从 0-x 范围运行。

几乎所有的属性都可以查到here

p <- plot_ly(mtcars, x = ~mpg, y = ~cyl, type = 'bar', orientation = 'h', 
             marker = list(color = viridis::viridis_pal(option = "C", direction =1)(max(mtcars$mpg) - min(mtcars$mpg) + 5))) %>% 
  config(displayModeBar = F) 
p <- layout(p, title = 'A plot',
       autosize = TRUE,
       margin = list(l = 50, r = 0, b = 20, t = 60, pad = 2), 
       xaxis = list(title = 'horizontal', ticks = "outside", ticklen = 5, tickwidth = 2, tickcolor = toRGB("black"),
                  showgrid = T, autorange = T, showticklabels = TRUE, zeroline = F,  showline = T),
       yaxis = list(title = 'vertical', ticks = "outside", ticklen = 5, tickwidth = 2, tickcolor = toRGB("black"),
                    showgrid = T, autorange = T, showticklabels = TRUE, zeroline = F,  showline = T),
       showlegend = T,  #show it or not
       legend = list(x = 100, y = 0.5), # can be used to position the legend
       scene = list(aspectratio = list(x = 1, y = 1, z = 1))) # can be used to keep the plot square, or not
p