防止 Plotly 中的标签重叠

raj*_*ind 5 r plotly

我正在R 中使用Plotly绘制气泡图。但是当我使用add_annotations给出标签时,标签重叠并且很难阅读它们。如何在plotly 中防止这种重叠。我试过“geom_label_repel”,但它不能很好地工作,因为它会出错。

我的代码是

plot_ly(bubbleChartData, x = ~Category1, y = ~Category2,  type = 'scatter', mode = 'markers', size = ~BubbleSize,
       color = ~Category3, colors = brewer.pal(8,"Dark2"),
      marker = list( sizemode = 'diameter'), text=~Category4) %>%

add_annotations( showarrow=F,xanchor="right",xref = "x",ax = 20,
                  ay = -40,
                   yref = "y",x = ~Category1, y = ~Category2, text=~Category4,font = list(size = 10))%>%
layout(title = '',font=list(size=10),
       xaxis = list(
         title = "",
         showgrid=FALSE,
         showline=FALSE,
         tickfont = list(
           size = 16,
           color = 'rgb(0,0,0)'),
         titlefont = list(
           size = 18,
           color = 'rgb(0,0,0)')),
       yaxis = list(
         title = "",
         showgrid=FALSE,
         showline=FALSE,
         titlefont = list(
           size = 18,
           color = 'rgb(0,0,0)'),
         tickfont = list(
           size = 16,
           color = 'rgb(0,0,0)')),
       showlegend = F)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明