使用r中的plotly()从条形图隐藏y轴线

时间:2019-06-26 07:05:25

标签: r r-plotly

我正在使用plot_ly()可视化水平条形图。 x轴的轴线不显示,但y轴显示。我不确定如何隐藏条形图的轴线。

使用的数据帧如下:

df <- data.frame("Grade" = c(9,10,11,12), "totalHours" = c(93,81,7,96),
                 "Count" = c(30,16,1,14), "average" = c(3.100,5.062,7.000,6.857))

用于可视化的plot_ly()调用如下:

plot_ly(df, x=df$average, y=df$Grade, 
        type="bar", color=~Grade, orientation = 'h') %>%
  add_text(text=round(df$average), hoverinfo='none', textposition = 'auto', showlegend = FALSE,
           textfont=list(size=12, color="black")) %>%
  layout(yaxis = list(showgrid = FALSE),showlegend=FALSE) 

对此有什么解决办法吗?

1 个答案:

答案 0 :(得分:0)

我认为即使打开计算机,计算机仍将其理解为xaxis。希望这对您有用:

Noax <- list(
  title = "",
  zeroline = FALSE,
  showline = FALSE,
  showticklabels = FALSE,
  showgrid = FALSE
)

plot_ly(df, x=df$average, y=df$Grade, 
        type="bar", color=~Grade, orientation = 'h') %>%
  add_text(text=round(df$average), hoverinfo='none', textposition = 'auto', showlegend = FALSE,
           textfont=list(size=12, color="black")) %>%
  layout(xaxis = Noax)

enter image description here