R - put shortcuts inside the pie chart

Using the pie function in R, labels appear outside the pie. Is there a way to place labels inside each piece of the pie chart?

 f=table(LETTERS[c(rep(1,7),rep(2,10),rep(3,5))]) pie(f) 

It shows how to do this with ggplot here place-labels-on-pie-chart . Is there no way to do this with the pie function?

Edit: In response to some comments about using pie charts, I would like to clarify my intention with them. I actually just use a pie chart as part of the scatter chart matrix to visualize the entire data frame for regression. The matrix is โ€‹โ€‹configured as follows:

  • Bottom panels
    Examples of correlation numbers with a background darker for higher absolute correlation.
  • Top panels
    • Scatterplots for numeric values โ€‹โ€‹numeric
    • Boxes for Numerical Coefficients
  • Diagonal panels
    • Normal Density Histograms for Numeric
    • Pie chart for coefficient

See, I need something for the factors diagonally and decided a pie chart. Anyway, I decided to leave the labels and unchecked all the axles. I rather used darker colors for large pieces of cake ... so maybe this may be a bad way to display information, but I think it works well for a factor variable, showing how the observations will be proportionally distributed between the levels of factors better, than a barrel. The figure below describes the diabetes data in the lars package.

diabetes data set

+5
source share
1 answer

I donโ€™t think there is an easy way to do this, since the positions of the labels are hardcoded - look at the end

 body(pie) if (!is.na(lab) && nzchar(lab)) { lines(c(1, 1.05) * P$x, c(1, 1.05) * P$y) text(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj = ifelse(P$x < 0, 1, 0), ...) } } title(main = main, ...) invisible(NULL) } 

But you can overwrite this section of the program

 # create a new pie function to save overwriting original newpie <- pie # Tweak the label positions - changed 1.1 to 0.7 # also commented out the lines function - so that the # small lines next to the labels are not plot newlbs <- quote(if (!is.na(lab) && nzchar(lab)) { #lines(c(1, 1.05) * P$x, c(1, 1.05) * P$y) text(0.7 * P$x, 0.7 * P$y, labels[i], xpd = TRUE, adj = ifelse(P$x < 0, 1, 0), ...) }) # add in the new lines of code - trial and error found the right position body(newpie)[[22]][[4]][[7]] <- newlbs newpie(f) 

Thus, it seems that the work is small, but it gets there, and you will need to work a bit on the corner or formatting the text.

(maybe there is an argument for this)

+4
source

Source: https://habr.com/ru/post/1202721/


All Articles