How do R Pie Charts and Bar Charts differ in their usage?
a) Pie charts show proportions of a whole, while bar charts compare frequencies or proportions of categories
b) Pie charts are used for time series data, while bar charts are for categorical data
c) Pie charts compare two variables, while bar charts show distributions
d) Pie charts are for continuous data, while bar charts are for discrete data
Answer:
a) Pie charts show proportions of a whole, while bar charts compare frequencies or proportions of categories
Explanation:
Pie charts and bar charts serve different purposes in data visualization. Pie charts are used to show proportions of a whole, with each slice representing a category’s contribution to the total. Bar charts, on the other hand, are used to compare the frequencies or proportions of different categories by displaying rectangular bars of varying heights or lengths.
# Example of a pie chart
slices <- c(30, 40, 20, 10)
labels <- c("Category A", "Category B", "Category C", "Category D")
pie(slices, labels = labels, col = rainbow(length(slices)), main = "Pie Chart Example")
# Example of a bar chart
counts <- c(5, 15, 25, 35)
categories <- c("A", "B", "C", "D")
barplot(counts, names.arg = categories, col = "lightblue", main = "Bar Chart Example", ylab = "Count")
In these examples, the pie chart visually represents each category’s proportion of the total, while the bar chart compares the counts of different categories. Pie charts are best used when you want to emphasize the relative sizes of parts to a whole, whereas bar charts are more effective for comparing the sizes of different groups.