str(lib)
## 'data.frame':    72 obs. of  6 variables:
##  $ faculty     : chr  "ศึกษาศาสตร์" "ศึกษาศาสตร์" "ศึกษาศาสตร์" "ศึกษาศาสตร์" ...
##  $ month       : chr  "ม.ค." "ก.พ." "มี.ค." "เม.ย." ...
##  $ borrows     : int  652 880 668 421 517 227 262 644 903 708 ...
##  $ students    : int  3200 3200 3200 3200 3200 3200 3200 3200 3200 3200 ...
##  $ satisfaction: num  4.1 3.8 3.4 3.6 4 3.9 4 4 3.9 3.4 ...
##  $ responses   : int  200 202 158 170 162 69 70 241 267 182 ...
head(lib)
##     faculty month borrows students satisfaction responses
## 1 ศึกษาศาสตร์  ม.ค.     652     3200          4.1       200
## 2 ศึกษาศาสตร์  ก.พ.     880     3200          3.8       202
## 3 ศึกษาศาสตร์  มี.ค.     668     3200          3.4       158
## 4 ศึกษาศาสตร์ เม.ย.     421     3200          3.6       170
## 5 ศึกษาศาสตร์  พ.ค.     517     3200          4.0       162
## 6 ศึกษาศาสตร์  มิ.ย.     227     3200          3.9        69


ข้อ 1 — คณะไหนใช้ห้องสมุดมากที่สุด (3 คะแนน)

df_q1 <- lib %>% 
  group_by(faculty) %>% 
  summarise(
    total_borrows = sum(borrows),
    total_students = first(students),
    borrow_ratio = total_borrows / total_students
  )


print(df_q1)
## # A tibble: 6 × 4
##   faculty      total_borrows total_students borrow_ratio
##   <chr>                <int>          <int>        <dbl>
## 1 พยาบาลศาสตร์           3930            650         6.05
## 2 มนุษยศาสตร์             6371           1800         3.54
## 3 วิทยาศาสตร์             7393           2400         3.08
## 4 วิศวกรรมศาสตร์          2098           1500         1.40
## 5 ศึกษาศาสตร์             7114           3200         2.22
## 6 เภสัชศาสตร์             3840            420         9.14
ggplot(df_q1, aes(x = reorder(faculty, -total_borrows), y = total_borrows)) +
  geom_col(fill = "steelblue") +  
  geom_text(aes(label = scales::comma(total_borrows)), vjust = -0.5, size = 3.5) + 
  scale_y_continuous(breaks = c(0, 4000, 8000), limits = c(0, 8500)) + 
  labs(title = "Total Borrows by Faculty", x = "Faculty", y = "Total Borrows") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

คำตอบ (3–4 บรรทัด — “มากที่สุด” ของคุณนับจากอะไร และทำไมเลือกนับแบบนั้น) #กราฟต้องการแสดงข้อมูลยอดการยืนของแต่ละคณะโดยที่คณะที่ยืนมากที่สุดคือคณะวิทยาศาสตร์และคณที่ยืมน้อยที่สุดคือคณะวิศวกรรมศาสตร์ >


ข้อ 2 — ควรจัดกิจกรรมเดือนไหน (3 คะแนน)

month_order <- c("ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.")

df_q2 <- lib %>%
  group_by(month) %>%
  summarise(total_borrows = sum(borrows)) %>%
  mutate(month = factor(month, levels = month_order)) %>%
  arrange(month)


print(df_q2)
## # A tibble: 12 × 2
##    month total_borrows
##    <fct>         <int>
##  1 ม.ค.           2732
##  2 ก.พ.           3737
##  3 มี.ค.           2919
##  4 เม.ย.          1880
##  5 พ.ค.           2348
##  6 มิ.ย.            966
##  7 ก.ค.           1095
##  8 ส.ค.           2895
##  9 ก.ย.           3790
## 10 ต.ค.           3118
## 11 พ.ย.           3243
## 12 ธ.ค.           2023
ggplot(df_q2, aes(x = month, y = total_borrows, group = 1)) +
  geom_line(color = "steelblue", size = 1) +
  geom_point(color = "darkblue", size = 2) +
  geom_text(aes(label = scales::comma(total_borrows)), vjust = -0.8, size = 3) +
  labs(
    title = "จำนวนการยืมหนังสือในแต่ละเดือน", 
    x = "เดือน", 
    y = "ยอดรวมการยืมทั้งหมด (ครั้ง)"
  ) +
  scale_y_continuous(limits = c(0, 4200)) +
  theme_minimal()

คำตอบ (2 บรรทัด — แนะนำเดือนไหน เพราะอะไร) #แนะนำให้จัดกิจกรรมใน เดือนกุมภาพันธ์และเดือนกันยายนเนื่องจากข้อมูลยอดรวมการยืมหนังสือพีกสูงที่สุดในรอบปี ซึ่งเป็นช่วงสอบกลางภาคและปลายภาคใน1ปีการศึกษา >


ข้อ 3 — หน้าที่ผู้อ่านกดดูเองได้ (4 คะแนน)

library(crosstalk)
library(plotly)
library(DT)
library(dplyr)


month_order <- c("ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ช.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.")
df_q3 <- lib %>%
  mutate(month = factor(month, levels = month_order)) %>%
  arrange(month)


shared_month <- SharedData$new(df_q3)


bscols(
  widths = c(12, 12, 12),
  
  
  filter_select(
    id = "select_month_filter", 
    label = " ขั้นที่ 1: คลิกเลือกเดือนที่ต้องการดูข้อมูลเปรียบเทียบรายคณะ:", 
    sharedData = shared_month, 
    group = ~month,
    multiple = FALSE
  ),
  
  
  plot_ly(
    shared_month, 
    x = ~faculty, 
    y = ~students, 
    type = 'bar', 
    marker = list(color = 'steelblue'),
    
    hoverinfo = "y", 
    text = ~scales::comma(students),
    textposition = 'outside' 
  ) %>% 
    layout(
      title = "กราฟเปรียบเทียบจำนวนนิสิตรายคณะในเดือนที่เลือก",
      xaxis = list(title = "คณะ"),
      yaxis = list(title = "จำนวนนิสิต (คน)", range = c(0, 3600)) 
    ),
  
  
  datatable(
    shared_month,
    options = list(
      pageLength = 6, 
      dom = 't',      
      autoWidth = TRUE
    ),
    colnames = c("คณะ", "เดือน", "ยอดการยืม (ครั้ง)", "จำนวนนิสิตในคณะ", "ความพึงพอใจ", "จำนวนผู้ตอบ")
  )
)


ข้อ 4 — ตรวจข้อสรุปของผู้บริหาร (3 คะแนน)

library(dplyr)
library(ggplot2)


month_order <- c("ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.")


df_pharmacy <- lib %>%
  filter(faculty == "เภสัชศาสตร์") %>%
  mutate(month = factor(month, levels = month_order)) %>%
  arrange(month)

yearly_avg <- round(mean(df_pharmacy$satisfaction, na.rm = TRUE), 2)  # ได้ค่า 4.74
total_resp <- sum(df_pharmacy$responses, na.rm = TRUE)                # ได้ค่า 29 คน (หรือตามจำนวนจริงในไฟล์)


ggplot(df_pharmacy, aes(x = month, y = satisfaction)) +
  geom_col(fill = "steelblue", na.rm = TRUE) + 
  
  
  geom_hline(yintercept = yearly_avg, color = "red", linetype = "dashed", size = 0.8) +
  
 
  annotate("label", x = 12.3, y = yearly_avg, label = "4.74", 
           fill = "red", color = "white", fontface = "bold", size = 3.5, label.padding = unit(0.15, "lines")) +
  
 
  annotate("label", x = 8, y = 0.6, 
           label = paste0("📊 สรุปผลทั้งปี คณะเภสัชศาสตร์\n",
                          "• ค่าเฉลี่ยรวมทั้งปี: ", yearly_avg, " คะแนน (ปัดเศษได้ 4.7)\n",
                          "• ผู้ตอบแบบสอบถามรวม: ", total_resp, " คน\n",
                          "• มีข้อมูลสูญหาย (NA) ในเดือน มิ.ย. และ ก.ค."), 
           fill = "white", color = "darkred", fontface = "bold", size = 3.2, hjust = 0) +
  
 
  geom_text(aes(label = ifelse(is.na(satisfaction), "ไม่มีคนตอบ\n(NA)", 
                               paste0(satisfaction, " คะแนน\n(", responses, " คน)"))), 
            vjust = -0.3, size = 2.8, fontface = "bold", color = "black") +
  
  labs(
    title = paste0("ความพึงพอใจรายเดือน คณะเภสัชศาสตร์ (เทียบกับเส้นเฉลี่ยรวมสีแดง ", yearly_avg, ")"),
    subtitle = "แสดงให้เห็นว่าคะแนนเหวี่ยงสูงเนื่องจากฐานคนตอบน้อยมาก และมีข้อมูลที่สูญหาย (NA)",
    x = "เดือน",
    y = "คะแนนความพึงพอใจเฉลี่ย"
  ) +

  scale_y_continuous(limits = c(0, 5.8), breaks = c(0, 1, 2, 3, 4, 5)) +
  theme_minimal()

ตัวเลข 4.7 ถูกไหม #ค่าที่ถูกต้องคือ4.74
>

ข้อสรุปนี้มีปัญหาอะไร (พร้อมตัวเลขยืนยัน) #มีค่าข้อมูลหายไป2เดือนและมีคนที่ตอบแบบสอบถามเพียง32คน จึงทำให้ค่าเฉลี่ยสูง >


ข้อ 5 — บันทึกการใช้ AI (2 คะแนน)

prompt ที่ใช้ (คัดลอกมาเต็ม ๆ อย่างน้อย 1 อัน) #ข้อ1

คำนวณข้อมูล

df_q1 <- lib %>% group_by(faculty) %>% summarise( total_borrows = sum(borrows), total_students = first(students), borrow_ratio = total_borrows / total_students )

แสดงตารางผลลัพธ์ใน Console

print(df_q1)

สร้างและแสดงกราฟแท่ง (Bar Chart)

ggplot(df_q1, aes(x = reorder(faculty, -total_borrows), y = total_borrows, fill = faculty)) + geom_col() + labs(title = “Total Borrows by Faculty”, x = “Faculty”, y = “Total Borrows”) + theme(axis.text.x = element_text(angle = 45, hjust = 1))

สิ่งที่แก้จากที่ AI ให้มา และทำไมต้องแก้ แก้สีขอกราฟที่เอไอให้มาจากตอนแรกที่เป็นสีรุ้งและมีคำอธิบายที่ทำหน้าที่ซ้อนทับกัน >



ถ้า knit ไม่ผ่าน เขียนไว้ตรงนี้ว่าติดตรงไหน