R Plotly隐藏了X轴 [英] R Plotly has X-axis hidden
问题描述
当我绘制r-plotly图表时,其x轴处于隐藏状态.以下是存在此问题的图表:
The r-plotly chart has its x-axis hidden when I plotted it. Below is the chart with this problem:
下面是我的代码:
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轴?
I am wondering if there is a way to avoid hidden x-axis?
此外,我想知道如何更改y轴的比例.
Also, I would like to know how to change the scale of y-axis.
例如,我不想在y轴上看到5.5、4.5 ...,而只能看到5、4、3 ...等.
For example, I do not want to see 5.5, 4.5 ..., but only 5, 4, 3 ... etc. on y-axis.
提前谢谢.
推荐答案
可以通过参数showline = T
更改该行,或者在某些情况下,可以使用
zeroline = T
取决于您的绘图是否实际在0-x范围内运行.
The line can be altered by the argument showline = T
or in some cases by using
zeroline = T
depending whether your plot actually runs from 0-x range.
几乎所有属性都可以在此处
almost all attributes can be looked up 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
这篇关于R Plotly隐藏了X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!