#dùng phím tắt Ctrl + Alt + I để chèn chunk
lung_cancer_data <- data.frame(
Method = c("Overall", "Endobronchial tumor", "Biopsy at endobronchial tumor site"),
Diagnosis_Rate = c(38.55, 51.06, 63.33)
)
library(ggplot2)
library(ggthemes)
# Vẽ biểu đồ cột
ggplot(lung_cancer_data, aes(x = reorder(Method, Diagnosis_Rate), y = Diagnosis_Rate, fill = Method)) +
geom_bar(stat = "identity", width = 0.2) + # Thu nhỏ cột
geom_text(aes(label = Diagnosis_Rate), vjust = -0.5, size = 5) + # Hiển thị giá trị trên cột
scale_fill_manual(values = c("#1E90FF", "#FF4500", "#2E8B57")) + # Chọn màu phù hợp với slide
labs(title = "Lung Cancer Diagnosis Rate",
x = "Diagnosis Method",
y = "Percentage (%)") +
theme_minimal() +
theme(legend.position = "none", # Ẩn chú thích
text = element_text(size = 14),
axis.text.x = element_text(angle = 30, hjust = 1)) + # Xoay nhãn trục X cho dễ đọc
ylim(0, 70) +
labs(title = "",
x = "",
y = "Percentage of lung cancer diagnosis (%)") +
theme_economist() +
theme(legend.position = "none") # Ẩn chú thích vì màu sắc đã phân biệt trên cột

ggsave("ten_file.png", width = 8, height = 4, dpi = 300)
# Create a dataframe with the data
symptom_data <- data.frame(
Symptom = c("Dry cough", "Hemoptysis", "Productive cough", "Chest pain", "Dyspnea",
"Hoarseness", "Dysphagia", "Palpable peripheral lymph nodes"),
UTP_Frequency = c(6, 8, 19, 22, 27, 2, 2, 6),
UTP_Percentage = c(16.22, 21.62, 51.35, 59.46, 72.97, 5.41, 5.41, 16.22),
Overall_Frequency = c(13, 15, 54, 47, 57, 3, 2, 9),
Overall_Percentage = c(13.54, 15.63, 56.25, 48.96, 59.38, 3.13, 2.08, 9.38)
)
# Display the data
print(symptom_data)
## Symptom UTP_Frequency UTP_Percentage
## 1 Dry cough 6 16.22
## 2 Hemoptysis 8 21.62
## 3 Productive cough 19 51.35
## 4 Chest pain 22 59.46
## 5 Dyspnea 27 72.97
## 6 Hoarseness 2 5.41
## 7 Dysphagia 2 5.41
## 8 Palpable peripheral lymph nodes 6 16.22
## Overall_Frequency Overall_Percentage
## 1 13 13.54
## 2 15 15.63
## 3 54 56.25
## 4 47 48.96
## 5 57 59.38
## 6 3 3.13
## 7 2 2.08
## 8 9 9.38
# Create a dataframe with the data
symptom_data <- data.frame(
Symptom = c("Dry cough", "Hemoptysis", "Productive cough", "Chest pain", "Dyspnea",
"Hoarseness", "Dysphagia", "Palpable peripheral lymph nodes"),
UTP_Frequency = c(6, 8, 19, 22, 27, 2, 2, 6),
UTP_Percentage = c(16.22, 21.62, 51.35, 59.46, 72.97, 5.41, 5.41, 16.22),
Overall_Frequency = c(13, 15, 54, 47, 57, 3, 2, 9),
Overall_Percentage = c(13.54, 15.63, 56.25, 48.96, 59.38, 3.13, 2.08, 9.38)
)
# Display the data
print(symptom_data)
## Symptom UTP_Frequency UTP_Percentage
## 1 Dry cough 6 16.22
## 2 Hemoptysis 8 21.62
## 3 Productive cough 19 51.35
## 4 Chest pain 22 59.46
## 5 Dyspnea 27 72.97
## 6 Hoarseness 2 5.41
## 7 Dysphagia 2 5.41
## 8 Palpable peripheral lymph nodes 6 16.22
## Overall_Frequency Overall_Percentage
## 1 13 13.54
## 2 15 15.63
## 3 54 56.25
## 4 47 48.96
## 5 57 59.38
## 6 3 3.13
## 7 2 2.08
## 8 9 9.38
# Load necessary library
library(ggplot2)
library(reshape2)
# Create the dataframe with percentages
symptom_data <- data.frame(
Symptom = c("Dry cough", "Hemoptysis", "Productive cough", "Chest pain", "Dyspnea",
"Hoarseness", "Dysphagia", "Palpable lymph nodes"),
UTP_Percentage = c(16.22, 21.62, 51.35, 59.46, 72.97, 5.41, 5.41, 16.22),
Overall_Percentage = c(13.54, 15.63, 56.25, 48.96, 59.38, 3.13, 2.08, 9.38)
)
# Convert data to long format for ggplot
symptom_long <- melt(symptom_data, id.vars = "Symptom",
variable.name = "Group", value.name = "Percentage")
# Create the bar chart with percentages
ggplot(symptom_long, aes(x = reorder(Symptom, Percentage), y = Percentage, fill = Group)) +
geom_bar(stat = "identity", position = "dodge", width = 0.8) + # Dodge bars for comparison
geom_text(aes(label = paste0(Percentage, "%")), vjust = -0.4, size = 4,
position = position_dodge(0.8)) + # Reduce text size on bars
scale_fill_manual(values = c("#1E90FF", "#FF4500"), labels = c("Lung cancer Group(N=37)", "Overall Group(N=96)")) + # Set colors
labs(title = "Symptoms",
x = "Symptoms",
y = "Percentage (%)",
fill = "Group") +
theme_economist() +
theme(axis.text.x = element_text(hjust = 1, size = 8), # Reduce text size of x-axis labels
axis.title = element_text(size = 8), # Adjust axis title size
legend.text = element_text(size = 8), # Adjust legend text size
legend.title = element_text(size = 8),
text = element_text(size = 10)) # Adjust general text size

ggsave("symptom.png", width = 10, height = 6, dpi = 300)
# Load necessary libraries
library(ggplot2)
library(reshape2)
# Create the dataframe with percentages
clinical_data <- data.frame(
Clinical_Feature = c("Triad of decreased signs",
"Lower airway obstruction syndrome",
"Mediastinal syndrome",
"Respiratory tract infection syndrome",
"Not recorded"),
LC_Percentage = c(32.43, 37.84, 10.81, 21.62, 16.22),
Overall_Percentage = c(22.92, 23.96, 6.25, 38.54, 16.67)
)
# Convert data to long format for ggplot
clinical_long <- melt(clinical_data, id.vars = "Clinical_Feature",
variable.name = "Group", value.name = "Percentage")
# Load necessary libraries
library(ggplot2)
library(reshape2)
# Create the dataframe with percentages
clinical_data <- data.frame(
Clinical_Feature = c("Triad of decreased signs",
"Lower airway obstruction syndrome",
"Mediastinal syndrome",
"Respiratory tract infection syndrome",
"Not recorded"), # Đưa cột này xuống cuối
UTP_Percentage = c(32.43, 37.84, 10.81, 21.62, 16.22),
Overall_Percentage = c(22.92, 23.96, 6.25, 38.54, 16.67)
)
# Convert data to long format for ggplot
clinical_long <- melt(clinical_data, id.vars = "Clinical_Feature",
variable.name = "Group", value.name = "Percentage")
# Factor to set the order manually (đảm bảo "Not recorded" ở ngoài cùng bên phải)
clinical_long$Clinical_Feature <- factor(clinical_long$Clinical_Feature,
levels = c("Triad of decreased signs",
"Lower airway obstruction syndrome",
"Mediastinal syndrome",
"Respiratory tract infection syndrome",
"Not recorded")) # "Not recorded" ở cuối
# Create the bar chart
ggplot(clinical_long, aes(x = Clinical_Feature, y = Percentage, fill = Group)) +
geom_bar(stat = "identity", position = "dodge", width = 0.7) + # Dodge bars for comparison
geom_text(aes(label = paste0(Percentage, "%")), vjust = -0.3, size = 4,
position = position_dodge(0.7)) + # Reduce text size on bars
scale_fill_manual(values = c("#1E90FF", "#FF4500"), labels = c("Lung cancer (N=37)", "Overall (N=96)"))+
labs(title = "Signs",
x = "",
y = "Percentage (%)",
fill = "Group") +
theme_economist() +
theme(axis.text.x = element_text(angle = 0, hjust = 0.5, size = 10), # Keep X-axis labels horizontal
axis.title = element_text(size = 12), # Adjust axis title size
legend.text = element_text(size = 10), # Adjust legend text size
legend.title = element_text(size = 12),
text = element_text(size = 12)) # Adjust general text size

ggsave("sign.png", width = 14, height = 6, dpi = 300)