Pie Chart Labels Cut off

独自空忆成欢 提交于 2019-12-10 15:22:39

问题


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

回答1:


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)


来源:https://stackoverflow.com/questions/35002772/pie-chart-labels-cut-off

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!