Page 253 - Data Science class 11
P. 253
• clockwise: This parameter contains the logical value which indicates whether the slices are drawn clockwise or in an
anti-clockwise direction.
• col: This parameter gives colours to the pie in the graph.
You will create a pie chart to compare the world’s five most populated cities in 2021. We know from Internet population
data that in World City Populations 2021, the five following cities are the most populous:
✶ Tokyo (Population: 37,435,191)
✶ Delhi (Population: 29,399,141)
✶ Shanghai (Population: 26,317,104)
✶ Sao Paulo (Population: 21,846,507)
✶ Mexico City (Population: 21,671,908)
Enter the following code snippet in the script panel:
# Create data for the graph.
x <- c(37.43, 29.4,26.32, 21.84,21.67)
labels <- c("Tokyo","Delhi", "Shanghai", "Sao Paulo", "Mexico")
# Give the chart file a name.
png(file = "city.png")
# Plot the chart.
pie(x,labels)
# Save the file.
dev.off()
After running the code, you will generate the following graph:
This chart will be modified to carry the title and have different colours:
# Create data for the graph.
x <- c(37.43, 29.4,26.32, 21.84)
labels <- c("Tokyo","Delhi", "Shanghai", "Sao Paulo")
# Give the chart file a name.
png(file = "city_title_colours1.jpg")
# Plot the chart with title and rainbow color pallet.
pie(x, labels, main = "Worlds four Bigest cities", col = rainbow(length(x)))
# Save the file.
dev.off()
Coding for Data Science Visualisation using R-Studio 251

