Let’s create more complex visualizations, such as a boxplot and a density plot.
Boxplot
rCopy code# Boxplot to visualize the distribution of weight by age group
ggplot(data, aes(x = factor(age > 30), y = weight)) +
geom_boxplot(fill = "lightblue") +
labs(title = "Boxplot of Weight by Age Group (Above/Below 30)",
x = "Age > 30",
y = "Weight (kg)") +
theme_minimal()
Density Plot
rCopy code# Density plot for height
ggplot(data, aes(x = height, fill = ..count..)) +
geom_density(alpha = 0.5) +
labs(title = "Density Plot of Height",
x = "Height (cm)",
y = "Density") +
theme_minimal()
Leave a Reply