饼图标签被截断

4
我在制作一个饼图时,某些标签被截断了。我想缩小绘图以容纳所有标签。以下是可复制的示例。
library(plotly)
plot_ly(type="pie",values=1:19,
        labels=c(101:119),textinfo="label+value+percent",
        textposition="outside",showlegend=F,marker=list(colors=c(
          "gray",
          "thistle",
          "red",
          "lightskyblue",
          "deeppink",
          "green",
          "gold",
          "brown",
          "purple",
          "orange",
          "cadetblue",
          "darkslategray",
          "burlywood",
          "yellow",
          "skyblue",
          "lightgreen",
          "hotpink",
          "lightgray",
          "blue"
        )))

不确定这是否有帮助..但肯定会缩小图形。domain=list(x=c(0.25,0.75), y=c(0.25,0.75)) - user20650
我只是随便试着玩了一下。它确实可以缩小图表,但由于标签太靠近,Plotly仍会将其中一些标签放得离饼图很远。可能还有其他参数可用于调整此功能。供参考,所有可添加到Plotly饼图中的参数都在此处记录 - eipi10
1个回答

2
你可以尝试这个方法。只需在layout()表达式中设置边距、高度和宽度即可。只要调整数字,直到达到你想要的效果为止。希望能帮到你。
m = list(
  l = 40,
  r = 40,
  b = 50,
  t = 50,
  pad = 0
)

plot_ly(type="pie",values=1:19, height = 25,
        labels=c(101:119),textinfo="label+value+percent",
        textposition="outside",showlegend=F,marker=list(colors=c(
          "gray",
          "thistle",
          "red",
          "lightskyblue",
          "deeppink",
          "green",
          "gold",
          "brown",
          "purple",
          "orange",
          "cadetblue",
          "darkslategray",
          "burlywood",
          "yellow",
          "skyblue",
          "lightgreen",
          "hotpink",
          "lightgray",
          "blue"
        ))) %>%
  layout(autosize = F, width = 800, height = 800, margin = m)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接