This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
ChickWeight
data(“ChickWeight”)
summary(ChickWeight)
unique_values_chick <- table(ChickWeight\(Chick) unique_values_diet <- table(ChickWeight\)Diet) cat(“Unique Chick values and counts:”) print(unique_values_chick) cat(“Unique Diet values and counts:”) print(unique_values_diet)
#total weight gained by each chick chick_weight_gain <- ChickWeight %>% group_by(Chick) %>% summarise(total_weight_gain = max(weight) - min(weight)) head(chick_weight_gain)
#visualsummary library(ggplot2) library(dplyr)
ggplot(ChickWeight, aes(x = weight)) + geom_histogram(fill = “lightblue”, color = “black”) + labs(title = “Distribution of Chick Weight”, x = “Weight”) + theme_minimal()
ggplot(ChickWeight, aes(x = Time, y = weight, color = Diet)) + geom_line() + labs(title = “Weight Over Time by Diet”, x = “Time (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 by 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()