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
library(dplyr)
library(ggplot2)
df <- read.csv("library_2568.csv", encoding = "UTF-8")
faculty_summary <- df %>%
group_by(faculty) %>%
summarise(
total_borrows = sum(borrows, na.rm = TRUE),
students = first(students)
) %>%
mutate(
borrows_per_student = total_borrows / students,
is_top = ifelse(borrows_per_student == max(borrows_per_student), "Top", "Normal")
)
p <- ggplot(faculty_summary, aes(x = reorder(faculty, borrows_per_student), y = borrows_per_student, fill = is_top)) +
geom_col(width = 0.65, show.legend = FALSE) +
coord_flip() +
geom_text(aes(label = sprintf("%.2f เล่ม/คน", borrows_per_student)),
hjust = -0.12, size = 5.6, fontface = "bold", color = "#1E293B") +
scale_fill_manual(values = c("Top" = "#EF4444", "Normal" = "#1B6CA8")) +
scale_y_continuous(limits = c(0, max(faculty_summary$borrows_per_student) * 1.28)) +
labs(
title = "อัตราการยืมหนังสือเฉลี่ยต่อคนแยกตามคณะ (ครั้ง/คน/ปี)",
subtitle = "เปรียบเทียบตามสัดส่วนความหนาแน่นของการใช้งานจริงต่อจำนวนนักศึกษา",
x = "คณะ",
y = "จำนวนการยืมเฉลี่ยต่อคน (เล่ม/คน)"
) +
theme_minimal(base_size = 16) +
theme(
plot.title.position = "plot",
plot.title = element_text(face = "bold", size = 16, color = "#0F172A", hjust = 0.5, margin = margin(b = 6)),
plot.subtitle = element_text(size = 13, color = "#475569", hjust = 0.5, margin = margin(b = 20)),
axis.title.x = element_text(size = 16, face = "bold", color = "#1E293B", margin = margin(t = 12)),
axis.title.y = element_text(size = 16, face = "bold", color = "#1E293B", margin = margin(r = 12)),
axis.text.y = element_text(size = 16, face = "bold", color = "#0F172A"),
axis.text.x = element_text(size = 13, color = "#475569"),
panel.grid.major.y = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = margin(20, 25, 20, 20)
)
print(p)
คำตอบ (3–4 บรรทัด — “มากที่สุด” ของคุณนับจากอะไร และทำไมเลือกนับแบบนั้น)
คณะเภสัชศาสตร์ มีอัตราการยืมสูงที่สุดถึง 9.14 เล่ม/คน/ปี (แม้จะมีนักศึกษาเพียง 420 คน) สูงกว่าคณะที่มียอดรวมสูงสุดอย่างวิทยาศาสตร์ (3.08 เล่ม/คน) ถึง 3 เท่า แสดงให้เห็นถึงความต้องการและพฤติกรรมการอ่านหนังสือเรียนที่เข้มข้น จึงควรพิจารณาเพิ่มงบหนังสือให้คณะเภสัชศาสตร์เป็นอันดับแรก
library(dplyr)
library(ggplot2)
library(plotly)
library(ggplot2)
library(plotly)
# 1. โหลดข้อมูล
df <- read.csv("library_2568.csv", encoding = "UTF-8")
# 2. กำหนดลำดับเดือนตามปฏิทิน ม.ค. ถึง ธ.ค.
month_order <- c("ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.",
"ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.")
# 3. รวมยอดยืมรายเดือนทั้งมหาวิทยาลัย (ใส่ .groups = "drop" ป้องกัน Error)
df_monthly <- df %>%
group_by(month) %>%
summarise(total_borrows = sum(borrows, na.rm = TRUE), .groups = "drop") %>%
mutate(month = factor(month, levels = month_order)) %>%
arrange(month)
# 4. วาดกราฟเส้นโทนสีตรงตามรูป
p2 <- ggplot(df_monthly, aes(x = month, y = total_borrows, group = 1,
text = paste0("<b>เดือน:</b> ", month,
"<br><b>ยอดยืมรวม:</b> ", format(total_borrows, big.mark=","), " ครั้ง"))) +
geom_line(color = "#B0B0B0", size = 1.3) +
geom_point(color = "#1F77B4", size = 3) +
labs(
title = "ควรจัดกิจกรรมในเดือน มิ.ย. เพื่อดึงดูดผู้ใช้บริการ เนื่องจากมียอดยืมต่ำสุดเพียง 966 ครั้ง",
x = "เดือน",
y = "ยอดยืมรวมทั้งมหาวิทยาลัย (ครั้ง)"
) +
theme_minimal(base_size = 11) +
theme(
plot.title = element_text(face = "bold", size = 11, color = "#1E293B", hjust = 0.5, margin = margin(b = 10)),
axis.title.x = element_text(face = "bold", size = 10, margin = margin(t = 8)),
axis.title.y = element_text(face = "bold", size = 10, margin = margin(r = 8)),
panel.grid.minor = element_blank()
)
# 5. แสดงผลแบบ Interactive Plotly
ggplotly(p2, tooltip = "text") %>%
config(displaylogo = FALSE)
คำตอบ (2 บรรทัด — แนะนำเดือนไหน เพราะอะไร)
ควรจัดกิจกรรมส่งเสริมการอ่านใน เดือนมิถุนายน ซึ่งมียอดการยืมหนังสือต่ำที่สุดในรอบปีเพียง 966 ครั้ง
library(ggplot2)
library(dplyr)
library(plotly)
library(crosstalk)
library(DT)
library(htmltools)
theme_set(theme_minimal(base_size = 11))
df <- read.csv("library_2568.csv", encoding = "UTF-8")
month_order <- c("ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.",
"ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.")
df <- df %>%
mutate(month = factor(month, levels = month_order)) %>%
arrange(month)
sd <- SharedData$new(df, key = ~paste(faculty, month))
p <- ggplot(sd, aes(x = month, y = borrows,
text = paste0("<b>คณะ:</b> ", faculty,
"<br><b>เดือน:</b> ", month,
"<br><b>ยอดยืม:</b> ", borrows, " ครั้ง"))) +
geom_point(colour = "#1B6CA8", alpha = 0.6, size = 2.5) +
labs(
title = "ยอดการยืมหนังสือรายเดือน",
x = "เดือน",
y = "ยอดการยืม (ครั้ง)"
) +
theme_minimal(base_size = 11) +
theme(
plot.title = element_text(face = "bold", size = 12, color = "#0F172A", hjust = 0.5),
axis.title = element_text(face = "bold", size = 10, color = "#334155")
)
bscols(
widths = c(3, 9),
filter_select("fac_filter", "เลือกคณะ:", sd, ~faculty),
list(
ggplotly(p, tooltip = "text", height = 320) %>%
layout(yaxis = list(autorange = TRUE)) %>%
config(displaylogo = FALSE),
htmltools::tags$br(),
datatable(sd, rownames = FALSE,
colnames = c("คณะ", "เดือน", "ยอดยืม (ครั้ง)", "จำนวนนักศึกษา", "ความพึงพอใจ", "ผู้ตอบแบบสอบถาม"),
options = list(pageLength = 6, dom = 'tp'))
)
)
ข้อมูลชุดนี้แสดงเพียงยอดยืมหนังสือในระบบห้องสมุด
ไม่ได้สะสมข้อมูลการนั่งอ่านหนังสือเล่มจริงในห้องสมุดโดยไม่ได้ทำการยืมออก
หรือการเข้าใช้งานฐานข้อมูลอิเล็กทรอนิกส์ (E-Books / Online Journals)
library(dplyr)
library(ggplot2)
df <- read.csv("library_2568.csv", encoding = "UTF-8")
survey_summary <- df %>%
group_by(faculty) %>%
summarise(
avg_sat = round(mean(satisfaction, na.rm = TRUE), 2),
total_responses = sum(responses, na.rm = TRUE)
)
ggplot(survey_summary, aes(x = reorder(faculty, -total_responses), y = total_responses, fill = (faculty == "เภสัชศาสตร์"))) +
geom_col(show.legend = FALSE, width = 0.55) +
scale_fill_manual(values = c("TRUE" = "#EF4444", "FALSE" = "#1B6CA8")) +
geom_text(aes(label = paste0(total_responses, " คน")), vjust = -0.5, size = 3.8, fontface = "bold") +
labs(
title = "คะแนนพึงพอใจ 4.7 ของคณะเภสัชศาสตร์มาจากผู้ตอบเพียง 32 คน (เฉลี่ยเดือนละ 2.6 คน) ซึ่งน้อยเกินไปจนไม่น่าเชื่อถือ",
x = "คณะ",
y = "จำนวนผู้ตอบแบบสอบถามรวมทั้งปี (คน)"
) +
theme_minimal(base_size = 11) +
theme(
plot.title.position = "plot",
plot.title = element_text(face = "bold", size = 11, color = "#1E293B", hjust = 0.5, margin = margin(b = 12)),
axis.title.x = element_text(face = "bold", size = 10, margin = margin(t = 8)),
axis.title.y = element_text(face = "bold", size = 10, margin = margin(r = 8)),
panel.grid.major.x = element_blank()
)
ตัวเลข 4.7 ถูกไหม
ค่าเฉลี่ยความพึงพอใจของคณะเภสัชศาสตร์จากทั้ง 10 เดือนที่มีผู้ตอบประเมินได้เท่ากับ 4.74 ซึ่งเมื่อปัดทศนิยมจะได้เท่ากับ 4.7 พอดี
ข้อสรุปนี้มีปัญหาอะไร (พร้อมตัวเลขยืนยัน)
คณะเภสัชศาสตร์มีนักศึกษาทั้งหมด 420 คน แต่มีผู้ตอบแบบสอบถามรวมทั้งปีเพียง 32 คน (คิดเป็นอัตราส่วนผู้ตอบแค่ 7.6% หรือเฉลี่ยเดือนละประมาณ 2.6 คนเท่านั้น และในเดือน มิ.ย. กับ ก.ค. ไม่มีผู้ตอบเลย) การนำผลประเมินจากคนเพียง 32 คนไปอ้างอิงว่าเป็นตัวแทนคนทั้งคณะ แล้วนำไปเป็นต้นแบบให้กับคณะอื่นที่มีผู้ตอบหลักพันคน จึงเป็นข้อสรุปที่ไม่สมเหตุสมผล
prompt ที่ใช้ (คัดลอกมาเต็ม ๆ อย่างน้อย 1 อัน)
library(dplyr)
library(ggplot2)
library(plotly)
df <- read.csv("library_2568.csv", encoding = "UTF-8")
month_order <- c("ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.",
"ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.")
df_monthly <- df %>%
group_by(month) %>%
summarise(total_borrows = sum(borrows, na.rm = TRUE)) %>%
mutate(month = factor(month, levels = month_order)) %>%
arrange(month)
max_val <- max(df_monthly$total_borrows)
max_month <- df_monthly$month[which.max(df_monthly$total_borrows)]
min_val <- min(df_monthly$total_borrows)
min_month <- df_monthly$month[which.min(df_monthly$total_borrows)]
title_text <- paste0("ยอดยืมหนังสือสูงสุดในเดือน ", max_month, " (", format(max_val, big.mark=","), " ครั้ง) ",
"และต่ำสุดในเดือน ", min_month, " (", format(min_val, big.mark=","), " ครั้ง)")
p2 <- ggplot(df_monthly, aes(x = month, y = total_borrows, group = 1,
text = paste0("<b>เดือน:</b> ", month,
"<br><b>ยอดยืมรวม:</b> ", format(total_borrows, big.mark=","), " ครั้ง"))) +
geom_line(color = "#B0B0B0", size = 1.3) +
geom_point(color = "#1F77B4", size = 3) +
labs(
title = title_text,
x = "เดือน",
y = "ยอดยืมรวมทั้งมหาวิทยาลัย (ครั้ง)"
) +
theme_minimal(base_size = 11) +
theme(
plot.title = element_text(face = "bold", size = 11, color = "#1E293B", hjust = 0.5, margin = margin(b = 10)),
axis.title.x = element_text(face = "bold", size = 10, margin = margin(t = 8)),
axis.title.y = element_text(face = "bold", size = 10, margin = margin(r = 8)),
panel.grid.minor = element_blank()
)
ggplotly(p2, tooltip = "text") %>%
config(displaylogo = FALSE)
สิ่งที่แก้จากที่ AI ให้มา และทำไมต้องแก้ > ให้ชื่อกราฟที่ไม่ใช่ข้อสรูปก็เลยเอามาแก้ใหม่เพื่อให้คำสวยงามขึ้น
ถ้า knit ไม่ผ่าน เขียนไว้ตรงนี้ว่าติดตรงไหน