# 1. Pastikan semua paket sudah siap
if (!require("tidyverse")) install.packages("tidyverse")
library(tidyverse)
library(ggplot2)

# 2. Masukkan data untuk jumlah daun
jumlah_daun <- tribble(
  ~Aplikasi, ~Komposisi, ~Mean, ~SE,
  "10", "0", 6.043, 0.537,
  "10", "20", 7.753, 0.397,
  "10", "40", 8.800, 0.188,
  "10", "60", 9.817, 0.249,
  "20", "0", 6.760, 0.181,
  "20", "20", 8.963, 0.518,
  "20", "40", 10.033, 0.102,
  "20", "60", 10.810, 0.364,
  "30", "0", 7.937, 0.140,
  "30", "20", 9.797, 0.489,
  "30", "40", 11.240, 0.419,
  "30", "60", 12.900, 0.459
) %>% mutate(Parameter = "Leaf Number")

# 3. Masukkan data untuk jumlah anakan
jumlah_anakan <- tribble(
  ~Aplikasi, ~Komposisi, ~Mean, ~SE,
  "10", "0", 1.989, 0.071,
  "10", "20", 2.427, 0.091,
  "10", "40", 2.863, 0.018,
  "10", "60", 2.997, 0.011,
  "20", "0", 2.122, 0.074,
  "20", "20", 2.883, 0.064,
  "20", "40", 3.108, 0.092,
  "20", "60", 3.401, 0.101,
  "30", "0", 2.484, 0.027,
  "30", "20", 3.132, 0.089,
  "30", "40", 3.401, 0.122,
  "30", "60", 3.791, 0.050
) %>% mutate(Parameter = "Tiller Number")

# 4. Masukkan data untuk tinggi tanaman
tinggi_tanaman <- tribble(
  ~Aplikasi, ~Komposisi, ~Mean, ~SE,
  "10", "0", 41.439, 0.484,
  "10", "20", 43.574, 1.991,
  "10", "40", 51.438, 0.378,
  "10", "60", 54.525, 0.756,
  "20", "0", 45.767, 0.697,
  "20", "20", 49.976, 0.875,
  "20", "40", 55.343, 0.171,
  "20", "60", 59.821, 0.331,
  "30", "0", 51.302, 0.902,
  "30", "20", 55.310, 0.524,
  "30", "40", 58.714, 0.465,
  "30", "60", 61.875, 0.622
) %>% mutate(Parameter = "Plant Height")

# 5. Gabungkan semua data
gabung_data <- bind_rows(jumlah_daun, jumlah_anakan, tinggi_tanaman)

# 6. Buat grafik faceted
ggplot(gabung_data, aes(x = Komposisi, y = Mean, group = Aplikasi, color = Aplikasi)) +
  geom_line(size = 1) +
  geom_point(size = 2.5) +
  geom_errorbar(aes(ymin = Mean - SE, ymax = Mean + SE), width = 0.2) +
  facet_wrap(~Parameter, scales = "free_y", ncol = 1) +
  labs(
    title = expression("Growth Parameters of " * italic("Pennisetum purpureum") * " cv. Mott"),
    x = "Biochar Composition (%)",
    y = "Mean ± SE",
    color = expression("Application Rate (tonnes ha"^{-1}*")")
  ) +
  theme_minimal(base_size = 10, base_family = "Times") +
  theme(
    legend.position = "right",  # legenda DI LUAR grafik
    legend.title = element_text(size = 9),
    legend.text = element_text(size = 8),
    axis.title = element_text(size = 10),
    axis.text = element_text(size = 9),
    strip.text = element_text(size = 10),
    plot.title = element_text(size = 11, face = "bold", hjust = 0.5),
    axis.text.x = element_text(angle = 0, hjust = 0.5)
  )

