Instalamos os pacotes tidyverse, ggpubr, table1, nortest, patchwork e abrimos o banco de dados lung.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggpubr)
library(table1)
## 
## Anexando pacote: 'table1'
## 
## Os seguintes objetos são mascarados por 'package:base':
## 
##     units, units<-
library (patchwork)
library(nortest)

library(readxl)
lung <- read_excel("lung(1).xlsx")

Codificando as cidades

lung$cidade[lung$cidade == 0] <- "Porto Alegre"
lung$cidade[lung$cidade == 1] <- "Canoas"
lung$cidade[lung$cidade == 2] <- "Guaiba"
lung$cidade[lung$cidade == 3] <- "Gravatai"

Transformando a variável cidade em fator

lung$cidade = as.factor(lung$cidade)

Transformando a variável Fumante

lung$tabagismo[lung$tabagismo == 0] <- "Não fumante"
lung$tabagismo[lung$tabagismo == 1] <- "Ex-fumante"
lung$tabagismo[lung$tabagismo == 2] <- "Fumante"
lung$tabagismo <- as.factor(lung$tabagismo)

Criação Tabela Demográfica

table1(~ idade + altura + peso + imc | cidade, data=lung)
Canoas
(N=75)
Gravatai
(N=75)
Guaiba
(N=75)
Porto Alegre
(N=75)
Overall
(N=300)
idade
Mean (SD) 35.6 (11.2) 29.8 (10.3) 36.1 (11.6) 34.0 (11.0) 33.9 (11.3)
Median [Min, Max] 35.7 [18.6, 62.9] 26.1 [18.1, 54.2] 34.8 [18.3, 55.9] 35.5 [18.0, 53.8] 33.0 [18.0, 62.9]
altura
Mean (SD) 175 (6.78) 175 (8.13) 172 (7.86) 173 (7.78) 174 (7.69)
Median [Min, Max] 175 [162, 196] 174 [150, 197] 172 [157, 197] 174 [157, 192] 174 [150, 197]
peso
Mean (SD) 82.8 (14.2) 81.1 (13.5) 80.8 (15.6) 82.0 (15.4) 81.7 (14.6)
Median [Min, Max] 82.0 [50.0, 132] 80.0 [54.0, 122] 80.0 [58.0, 140] 82.0 [54.0, 125] 80.0 [50.0, 140]
imc
Mean (SD) 27.0 (3.96) 26.6 (4.32) 27.2 (4.37) 26.9 (5.70) 26.9 (4.62)
Median [Min, Max] 26.6 [17.7, 39.0] 25.8 [18.6, 41.7] 26.1 [19.6, 40.9] 27.0 [0.00257, 38.7] 26.4 [0.00257, 41.7]

Tabela 2 - Função pulmonar

table1(~ fvcz + fev1z + fev1fvcz + fef2575z | cidade, data=lung)
Canoas
(N=75)
Gravatai
(N=75)
Guaiba
(N=75)
Porto Alegre
(N=75)
Overall
(N=300)
fvcz
Mean (SD) -0.577 (0.830) -1.24 (1.02) -0.921 (0.920) -0.980 (1.02) -0.930 (0.974)
Median [Min, Max] -0.537 [-2.84, 1.26] -1.06 [-3.61, 0.700] -0.872 [-3.82, 1.33] -0.975 [-4.11, 1.61] -0.883 [-4.11, 1.61]
fev1z
Mean (SD) -0.493 (0.848) -1.16 (1.02) -0.700 (0.847) -0.760 (1.05) -0.779 (0.972)
Median [Min, Max] -0.467 [-2.73, 1.37] -0.980 [-4.13, 1.23] -0.589 [-3.39, 1.57] -0.772 [-3.20, 1.34] -0.724 [-4.13, 1.57]
fev1fvcz
Mean (SD) 0.192 (1.13) 0.158 (1.30) 0.444 (1.03) 0.423 (1.18) 0.304 (1.16)
Median [Min, Max] 0.173 [-2.57, 2.46] 0.176 [-3.65, 3.74] 0.470 [-2.51, 3.61] 0.348 [-2.48, 3.55] 0.319 [-3.65, 3.74]
fef2575z
Mean (SD) -0.137 (0.899) -0.491 (1.09) -0.0772 (0.782) -0.184 (0.954) -0.222 (0.946)
Median [Min, Max] -0.178 [-2.57, 1.59] -0.440 [-4.38, 1.68] -0.0775 [-2.53, 1.42] -0.126 [-2.36, 1.93] -0.175 [-4.38, 1.93]

Testes de normalidade

lillie.test(lung$fvcz)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  lung$fvcz
## D = 0.058471, p-value = 0.01504
lillie.test(lung$fev1z)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  lung$fev1z
## D = 0.050336, p-value = 0.06404
lillie.test(lung$fev1fvcz)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  lung$fev1fvcz
## D = 0.050541, p-value = 0.06195
lillie.test(lung$fef2575z)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  lung$fef2575z
## D = 0.056845, p-value = 0.02054

Testando a diferença entre as cidades

kruskal.test(lung$cidade~lung$fvcz)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  lung$cidade by lung$fvcz
## Kruskal-Wallis chi-squared = 299, df = 298, p-value = 0.4728
kruskal.test(lung$cidade~lung$fev1z)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  lung$cidade by lung$fev1z
## Kruskal-Wallis chi-squared = 299, df = 298, p-value = 0.4728
kruskal.test(lung$cidade~lung$fev1fvcz)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  lung$cidade by lung$fev1fvcz
## Kruskal-Wallis chi-squared = 299, df = 298, p-value = 0.4728
kruskal.test(lung$cidade~lung$fef2575z)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  lung$cidade by lung$fef2575z
## Kruskal-Wallis chi-squared = 299, df = 298, p-value = 0.4728

Houve diferença entre as cidades. Agora, vamos para o post-hoc

pairwise.wilcox.test(lung$fvcz, lung$cidade, t.ajust.method="bonferroni")
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  lung$fvcz and lung$cidade 
## 
##              Canoas Gravatai Guaiba
## Gravatai     0.0013 -        -     
## Guaiba       0.1360 0.2300   -     
## Porto Alegre 0.0450 0.4297   0.5011
## 
## P value adjustment method: holm
pairwise.wilcox.test(lung$fev1z, lung$cidade, t.ajust.method="bonferroni")
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  lung$fev1z and lung$cidade 
## 
##              Canoas  Gravatai Guaiba 
## Gravatai     0.00026 -        -      
## Guaiba       0.32408 0.01529  -      
## Porto Alegre 0.22813 0.14384  0.50107
## 
## P value adjustment method: holm
pairwise.wilcox.test(lung$fev1fvcz, lung$cidade, t.ajust.method="bonferroni")
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  lung$fev1fvcz and lung$cidade 
## 
##              Canoas Gravatai Guaiba
## Gravatai     1.00   -        -     
## Guaiba       0.70   0.41     -     
## Porto Alegre 0.70   0.70     1.00  
## 
## P value adjustment method: holm
pairwise.wilcox.test(lung$fef2575z, lung$cidade, t.ajust.method="bonferroni")
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  lung$fef2575z and lung$cidade 
## 
##              Canoas Gravatai Guaiba
## Gravatai     0.208  -        -     
## Guaiba       1.000  0.035    -     
## Porto Alegre 1.000  0.285    1.000 
## 
## P value adjustment method: holm

Gráfico 1 - Box Plot da função pulmonar por cidade

graf1 <- ggplot(lung, aes(x=cidade, y= fvcz) ) + 
  geom_boxplot() + 
  labs(x="Cidade", y="FEV1z") +
  theme_classic()

graf2 <- ggplot(lung, aes(x=cidade, y= fev1z) ) + 
  geom_boxplot() + 
  labs(x="Cidade", y="FEV1z") +
  theme_classic()

graf3 <- ggplot(lung, aes(x=cidade, y= fev1fvcz) ) + 
  geom_boxplot() + 
  labs(x="Cidade", y="FEV1/FVCz") +
  theme_classic()

graf4 <- ggplot(lung, aes(x=cidade, y= fef2575z) ) + 
  geom_boxplot() + 
  labs(x="Cidade", y="FEF25/75") +
  theme_classic()

Juntando os gráficos

Para isso, precisamos juntar como patchowork, mas primeiro, cada grafico tem que ter um nome

figura1 <- (graf1 | graf2) / (graf3 | graf4)
figura1