2025-10-19

Flower Data Analysis 🌸

Exploring the Relationship Between Width and Leaf Area

Slide with Flower Information

summary(flowers)
##        id            treat             nitrogen             height      
##  Min.   :  1.00   Length:100         Length:100         Min.   : 1.000  
##  1st Qu.: 25.75   Class :character   Class :character   1st Qu.: 4.825  
##  Median : 50.50   Mode  :character   Mode  :character   Median : 8.300  
##  Mean   : 50.50                                         Mean   : 8.418  
##  3rd Qu.: 75.25                                         3rd Qu.:12.300  
##  Max.   :100.00                                         Max.   :14.900  
##      block         leafarea         width           length     
##  Min.   :1.00   Min.   :10.30   Min.   :2.000   Min.   :10.10  
##  1st Qu.:2.00   1st Qu.:22.52   1st Qu.:3.000   1st Qu.:14.68  
##  Median :3.00   Median :35.80   Median :4.000   Median :19.40  
##  Mean   :2.58   Mean   :35.25   Mean   :3.953   Mean   :18.58  
##  3rd Qu.:3.25   3rd Qu.:50.10   3rd Qu.:4.950   3rd Qu.:22.00  
##  Max.   :4.00   Max.   :59.40   Max.   :6.000   Max.   :25.00
head(flowers)
##   id   treat nitrogen height block leafarea width length
## 1  1     tip   medium    4.1     3     51.2   3.4   19.4
## 2  2 control      low    7.9     4     47.3   3.5   23.4
## 3  3 control      low    5.4     2     44.0   5.6   10.1
## 4  4     tip     high    7.9     3     12.9   5.2   24.4
## 5  5 control      low    2.3     1     50.6   2.5   14.1
## 6  6 control   medium   11.4     2     16.3   2.3   21.7

Plot using ploty

plot(flowers$width, flowers$leafarea,
     main = "Scatter Plot of Width vs Leaf Area",
     xlab = "Width",
     ylab = "Leaf Area",
     pch = 19,      
     col = "deeppink",
     lwd = 2)

Line Formula

The formula for a line is \(y = mx + b\).

Scatterplot - ggplot1

## Boxplot - ggplot #2

ggplot(flowers, aes(treat, leafarea, fill = treat)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.6) +
labs(title = "Leaf Area by Treatment",
x = "Treatment", y = "Leaf Area") +
theme_minimal() +
theme(
    plot.background  = element_rect(fill = "#ffe6f2", color = NA),
    panel.background = element_rect(fill = "#fff0f5", color = NA),
    panel.grid.major = element_line(color = "#f8bbd0", linewidth = 0.4),
    panel.grid.minor = element_line(color = "#fce4ec", linewidth = 0.2),
    axis.title       = element_text(color = "#ad1457", face = "bold"),
    axis.text        = element_text(color = "#880e4f"),
    plot.title       = element_text(color = "#ad1457", face = "bold", hjust = 0.5)
  )

## Boxplot Formula

The interquartile range (IQR) measures the middle 50% of the data:

\[ IQR = Q_3 - Q_1 \]

The Reusable Code I Use for My Pink Theme

# This is able to show on the slide becuase we set eval to false so we dont run the code and echo true to show the code
theme(
  plot.background  = element_rect(fill = "#ffe6f2", color = NA),
  panel.background = element_rect(fill = "#fff0f5", color = NA),
  panel.grid.major = element_line(color = "#f8bbd0", linewidth = 0.4),
  panel.grid.minor = element_line(color = "#fce4ec", linewidth = 0.2),
  axis.title       = element_text(color = "#ad1457", face = "bold"),
  axis.text        = element_text(color = "#880e4f"),
  plot.title       = element_text(color = "#ad1457", face = "bold", hjust = 0.5)
)