My Blog

My WordPress Blog

My Blog

My WordPress Blog

Advanced Visualization with ggplot2

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()
Advanced Visualization with ggplot2

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top