Homework 2.1

Author

V Duckworth

Q1 Generating Random Data

Load necessary library

library.(“tidyverse”)

Set seed for reproducibility

```{r}set.seed(123)

Generate random data

```{r} x <- rnorm(1000, mean = 50, sd = 10) id <- 1:1000

Create dataframe

```{r} df <- data.frame(id, x)

Display first few rows

```{r} head(df)

#Q2 & 3 Plotting and Customizing the Data # Histogram with Normally Distributed Data ggplot2(data=df, aes(x=x)) + geom_histogram(color = “black”, fill = “blue”, alpha = 0.6, bins = 30) + geom_vline(aes(xintercept = mean(x)), color = “red”, linetype = “dashed”) + labs(title = “Histogram of Normally Distributed Data”, x = “Values”, y = “Frequency”) + theme_minimal()

#Q4 Density Plot

ggplot2(data=df, aes(x=x)) + geom_density(fill = “lightblue”, alpha = 0.6) + geom_vline(aes(xintercept = mean(x)), color = “red”, linetype = “dashed”) + labs(title = “Density Plot of Normally Distributed Data”, x = “Values”, y = “Density”) + theme_minimal()