Pie chart displaying wrong percentages

Hi all.

I am trying to create a pie chart. The output percentages on the chart are wrong and do not correlate with the sizes of the slices - big slices are 18% and small ones are 65%, for example. Help with this would be really appreciated!

slices4 <- c(87242182, 21598297, 11635335, 4734527, 2633893, 1337270, 1977707)
lbls4 <- c("Deionised water production", "Wastewater Treatment", "KCl Production","Blasting","Other","Treatment of salt from potash mine","Remaining processes (<0.1%)")
pie(slices4, labels = "lbls4")
lbls4 <- paste(lbls4, pct) # add percents to labels
lbls4 <- paste(lbls4,"%",sep="") # ad % to labels
pie(slices4, col=c("#67001f", "#b2182b", "#d6604d", "#f4a582", "#fddbc7", "#d1e5f0", "#92c5de"),labels = lbls4)

In your third line, setting labels = "labels4" assigns that word as the only label. You also never define the pct variable. Replace that line with something like pct <- round(100*slices4/sum(slices4)).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.