Page 254 - Data Science class 11
P. 254
When the above code snippet is run, it will create a Console panel:
This also prints a chart separately, as shown below.
Slice Percentages and Chart Legend
You can also add slice percentage and a chart legend by creating additional chart variables.
Enter the following code snippet in the script panel:
# Create data for the graph.
x <- c(37.43, 29.4,26.32, 21.84)
labels <- c("Tokyo","Delhi", "Shanghai", "Sao Paulo")
piepercent<- round(100*x/sum(x), 1)
# Give the chart file a name.
png(file = "city_percentage_legends16.jpg")
# Plot the chart.
pie(x, labels = piepercent, main = "World's four Biggest cities",col =
rainbow(length(x)))
legend("topright", c("Tokyo","Delhi", "Shanghai", "Sao Paulo"), cex = 0.8,
fill = rainbow(length(x)))
# Save the file.
dev.off()
252 Touchpad Data Science-XI

