如何将标签放置在更远离R中的饼形图的位置?

slices <- c(10, 12, 4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct) # add percents to labels
lbls <- paste(lbls,"%",sep="") # ad % to labels
pie(slices,labels = lbls, col=rainbow(length(lbls)), radius=.2)


r - 如何将标签放置在饼状图的更远处-LMLPHP

最佳答案

您可以修改pie功能行50-54并将其另存为新功能pie2

类型

pie


将行50-54更改为

if (!is.na(lab) && nzchar(lab)) {
  lines(c(1, 1.35) * P$x, c(1, 1.35) * P$y)
  text(1.5 * P$x, 1.5 * P$y, labels[i], xpd = TRUE,
       adj = ifelse(P$x < 0, 1, 0), ...)
}


更改行长(默认= 1.05

  lines(c(1, 1.35) * P$x, c(1, 1.35) * P$y)


更改因子(默认= 1.1

  text(1.5 * P$x, 1.5 * P$y, labels[i], xpd = TRUE,
       adj = ifelse(P$x < 0, 1, 0), ...)


现在定义pie2并运行新功能

pie2(slices,labels = lbls, col=rainbow(length(lbls)), radius=.2)


r - 如何将标签放置在饼状图的更远处-LMLPHP

08-20 04:22