lung_data1 <- data.frame(
  Variable = c( "Lower airway obstruction syndrome",  
                "Pleural invasion", 
               "Left upper lobe bronchus (bronchoscopy)", 
               "Biopsy site"),
  OddsRatio = c(3.979, 5.997, 5.563, 4.967),
  LowerCI = c(1.313, 1.444, 1.806, 1.746),
  UpperCI = c(12.922, 28.472, 18.720, 15.213),
  Significance = c("Yes", "Yes", "Yes", "Yes"),
  pvalue = c(0.01675,0.01655,0.00368,0.00340)
)

# Hiển thị dữ liệu
print(lung_data1)
##                                  Variable OddsRatio LowerCI UpperCI
## 1       Lower airway obstruction syndrome     3.979   1.313  12.922
## 2                        Pleural invasion     5.997   1.444  28.472
## 3 Left upper lobe bronchus (bronchoscopy)     5.563   1.806  18.720
## 4                             Biopsy site     4.967   1.746  15.213
##   Significance  pvalue
## 1          Yes 0.01675
## 2          Yes 0.01655
## 3          Yes 0.00368
## 4          Yes 0.00340
# Cài đặt thư viện nếu chưa có
#install.packages("ggplot2")  
#install.packages("ggtext")  # Hỗ trợ hiển thị text đẹp hơn
library(ggplot2)
library(ggtext)
library(ggthemes)
# Vẽ Forest plot
plot<- ggplot(lung_data1, aes(y = reorder(Variable, OddsRatio), x = OddsRatio)) +
  geom_point(size = 3, color = "blue") +  # Điểm thể hiện OR
  geom_errorbarh(aes(xmin = LowerCI, xmax = UpperCI), height = 0.3, color = "blue") + # Thanh error bar
  geom_vline(xintercept = 1, linetype = "dashed", color = "red") + # Đường tham chiếu tại OR = 1
  labs(x = "Odds Ratio (95% CI)", y = "Variable", title = "Forest Plot of Logistic Regression") +
  
  # Hiển thị giá trị OR và p-value
  geom_text(aes(label = sprintf("OR = %.2f\np = %.3f", OddsRatio, pvalue)), 
            hjust = -0.1, size = 4, color = "gray70") +
  
  theme_economist() +
  theme(axis.text.y = element_text(size = 12))
ggsave("forest4bien.png", plot = plot, width = 8, height = 6, dpi = 300)