饼图标签被切掉

问题描述:

我正在制作一个饼图,某些标签被剪掉了.我想缩小地块以容纳所有标签.以下是可重现的示例.

I'm making a pie chart, and some of the labels get cut off. I'd like to shrink the plot to accommodate all the labels. Below is a reproducible example.

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"
        )))

您可以尝试一下.只需在layout()表达式中设置边距,高度和宽度.只是玩数字游戏,直到获得想要的东西.希望对您有所帮助.

You could try this. Just set the margin, height and width in your layout() expression. Just play with the numbers until you get what you want. Hope it helps.

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)