buhtz buhtz - 1 year ago 90
R Question

Control the gap of pie labels in R?

t = table(iris$Species)
pie(t, labels=rownames(t))

This draws a simple
. I want that the labels are a little bit more away from the pie. I checked the
docu but I think I don't understand it completly and I missed the option for that.

This question is explicite about R's own
and not related to any other extern R package.

Answer Source

I don't think you can really do this with the pie function. If you look at View(pie) you'll see that the labels are drawn using the text function. This means that they are not really axis labels, and that par has little effect on them. You could try to do stuff by using the arguments of the text function (i.e. pos = 2, offset = 1) but this will affect all labels in the exact same way and results in warnings. To me it seems that the only way is the stupid way by adding some spaces before/ after labels. ie:

t = table(iris$Species)
nms = rownames(t)
# spaces needed after the labels
nms[2] = paste0(nms[2], strrep(' ', 7)) 
# spaces needed before the labels
nms[c(1, 3)] = paste0(strrep(' ', 7), nms[c(1, 3)])
pie(t, labels = nms)

If you want to a better solution, you could rewrite the pie function to be a bit more flexible or use a different package.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download