问题
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