R Markdown

#Load the ChickWeight dataset
data(ChickWeight)
summary(ChickWeight)
##      weight           Time           Chick     Diet   
##  Min.   : 35.0   Min.   : 0.00   13     : 12   1:220  
##  1st Qu.: 63.0   1st Qu.: 4.00   9      : 12   2:120  
##  Median :103.0   Median :10.00   20     : 12   3:120  
##  Mean   :121.8   Mean   :10.72   10     : 12   4:118  
##  3rd Qu.:163.8   3rd Qu.:16.00   17     : 12          
##  Max.   :373.0   Max.   :21.00   19     : 12          
##                                  (Other):506
library(summarytools)

# Select 10 columns from the dataset
selected_column1 <- c("weight", "Time")
selected_column2 <-  c("Chick", "Diet")

# Create a subset of the dataset with the selected columns
subset_data1 <- ChickWeight[, selected_column1]
subset_data2 <- ChickWeight[, selected_column2]
# Generate summaries for the selected columns
summary_data1 <- summary(subset_data1)
print(summary_data1)
##      weight           Time      
##  Min.   : 35.0   Min.   : 0.00  
##  1st Qu.: 63.0   1st Qu.: 4.00  
##  Median :103.0   Median :10.00  
##  Mean   :121.8   Mean   :10.72  
##  3rd Qu.:163.8   3rd Qu.:16.00  
##  Max.   :373.0   Max.   :21.00
summary_data2 <- summary(subset_data2)
print(summary_data2)
##      Chick     Diet   
##  13     : 12   1:220  
##  9      : 12   2:120  
##  20     : 12   3:120  
##  10     : 12   4:118  
##  17     : 12          
##  19     : 12          
##  (Other):506
# Calculate the average weight by Time and Diet
agg_data <- aggregate(weight ~ Time + Diet, data = ChickWeight, FUN = mean)
print(agg_data)
##    Time Diet    weight
## 1     0    1  41.40000
## 2     2    1  47.25000
## 3     4    1  56.47368
## 4     6    1  66.78947
## 5     8    1  79.68421
## 6    10    1  93.05263
## 7    12    1 108.52632
## 8    14    1 123.38889
## 9    16    1 144.64706
## 10   18    1 158.94118
## 11   20    1 170.41176
## 12   21    1 177.75000
## 13    0    2  40.70000
## 14    2    2  49.40000
## 15    4    2  59.80000
## 16    6    2  75.40000
## 17    8    2  91.70000
## 18   10    2 108.50000
## 19   12    2 131.30000
## 20   14    2 141.90000
## 21   16    2 164.70000
## 22   18    2 187.70000
## 23   20    2 205.60000
## 24   21    2 214.70000
## 25    0    3  40.80000
## 26    2    3  50.40000
## 27    4    3  62.20000
## 28    6    3  77.90000
## 29    8    3  98.40000
## 30   10    3 117.10000
## 31   12    3 144.40000
## 32   14    3 164.50000
## 33   16    3 197.40000
## 34   18    3 233.10000
## 35   20    3 258.90000
## 36   21    3 270.30000
## 37    0    4  41.00000
## 38    2    4  51.80000
## 39    4    4  64.50000
## 40    6    4  83.90000
## 41    8    4 105.60000
## 42   10    4 126.00000
## 43   12    4 151.40000
## 44   14    4 161.80000
## 45   16    4 182.00000
## 46   18    4 202.90000
## 47   20    4 233.88889
## 48   21    4 238.55556
#visualsummary 
library(ggplot2) 
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#Histogram of Weight
ggplot(ChickWeight, aes(x = weight)) +
  geom_histogram(fill = "lightblue", color = "black") +
  labs(title = "Distribution of Chick Weight", x = "Weight") +
  theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#Weight Over Time using line plot
ggplot(ChickWeight, aes(x = Time, y = weight, color = Diet)) +
  geom_line() +
  labs(title = "weight over time by diet", x = "time in days", y = "weight") +
  theme_minimal()

#Weight vs Diet - Boxplot 
ggplot(ChickWeight, aes(x = as.factor(Diet), y = weight, fill = as.factor(Diet))) +
  geom_boxplot() + 
  labs(title = "weight distribution vs diet", x = 'diet', y = "weight") +
  theme_minimal()

#Scatterplot of Weight vs. Time 
ggplot(ChickWeight, aes(x = Time, y = weight, color = Diet)) +
  geom_point() + 
  labs(title = "“Scatterplot of Weight vs. Time by Diet”", x = "“Time (days)”", y = "“Weight”") +
  theme_minimal()