Task 0. Getting started
- Open the R Markdown template and put your name in the YAML
header
Task 1. Load the two datasets
- Load the two datasets into R
- Assign descriptive names to the datasets
# Add your codes (Please use #comments to organize codes)
household <- read.csv("hhdata.csv")
individual <- read.csv("inddata.csv")
Task 2. Prepare the datasets
- Convert variables into sensible formats
- Check out the structure of two datasets
- Check out the values of all the variables
- Change the values of ‘95+’ in variable age to ‘95’
- Convert variable urbanrural, wealthindex, sex, education into factor
variables with reasonably ordered levels, using dplyr
- Convert variables age, weight, height, all the blood pressure
measurements into numeric variables, using dplyr
- Create unique identifier
- Create unique identifier for individuals in both datasets, by
combining the column ‘clusterno’, ‘householdno’ and ‘individualno’ with
underscore (e.g. 1_4_1)
- Create unique identifier for households in both datasets, by
combining the column ‘clusterno’ and ‘householdno’ with underscore
(e.g. 1_4)
- Calculate the number of unique clusters, households and individuals
in both datasets
# Add your codes (Please use #comments to organize codes)
# structure of two datasets:
str(household)
## 'data.frame': 89819 obs. of 8 variables:
## $ individualno: int 1 2 3 4 5 1 2 3 4 5 ...
## $ clusterno : int 1 1 1 1 1 1 1 1 1 1 ...
## $ householdno : int 4 4 4 4 4 8 8 8 8 8 ...
## $ urbanrural : chr "rural" "rural" "rural" "rural" ...
## $ day : int 5 5 5 5 5 7 7 7 7 7 ...
## $ month : int 11 11 11 11 11 11 11 11 11 11 ...
## $ year : int 2017 2017 2017 2017 2017 2017 2017 2017 2017 2017 ...
## $ wealthindex : chr "poorest" "poorest" "poorest" "poorest" ...
str(individual)
## 'data.frame': 89819 obs. of 18 variables:
## $ individualno : int 1 2 3 4 5 1 2 3 4 5 ...
## $ clusterno : int 1 1 1 1 1 1 1 1 1 1 ...
## $ householdno : int 4 4 4 4 4 8 8 8 8 8 ...
## $ sex : chr "" "" "" "" ...
## $ age : chr "" "" "" "" ...
## $ weight_kg : chr "" "" "" "" ...
## $ height_mm : chr "" "" "" "" ...
## $ education : chr "" "" "" "" ...
## $ bp_measurement_1_consent : chr "" "" "" "" ...
## $ bp_measurement_1_systolic : chr "" "" "" "" ...
## $ bp_measurement_1_diastolic: chr "" "" "" "" ...
## $ bp_ever_measured : chr "" "" "" "" ...
## $ bp_ever_diagnosed : chr "" "" "" "" ...
## $ bp_taking_medicine : chr "" "" "" "" ...
## $ bp_measurement_2_systolic : chr "" "" "" "" ...
## $ bp_measurement_2_diastolic: chr "" "" "" "" ...
## $ bp_measurement_3_systolic : chr "" "" "" "" ...
## $ bp_measurement_3_diastolic: chr "" "" "" "" ...
## household variables
kable(summary(household), "html") %>%
kable_paper(bootstrap_options = "striped", full_width = F)
|
|
individualno
|
clusterno
|
householdno
|
urbanrural
|
day
|
month
|
year
|
wealthindex
|
|
|
Min. : 1.000
|
Min. : 1.0
|
Min. : 1.00
|
Length:89819
|
Min. : 1.00
|
Min. : 1.000
|
Min. :2017
|
Length:89819
|
|
|
1st Qu.: 2.000
|
1st Qu.:160.0
|
1st Qu.: 30.00
|
Class :character
|
1st Qu.: 6.00
|
1st Qu.: 2.000
|
1st Qu.:2017
|
Class :character
|
|
|
Median : 3.000
|
Median :340.0
|
Median : 60.00
|
Mode :character
|
Median :12.00
|
Median :10.000
|
Median :2017
|
Mode :character
|
|
|
Mean : 3.288
|
Mean :340.3
|
Mean : 64.27
|
NA
|
Mean :15.09
|
Mean : 6.657
|
Mean :2017
|
NA
|
|
|
3rd Qu.: 4.000
|
3rd Qu.:518.0
|
3rd Qu.: 93.00
|
NA
|
3rd Qu.:25.00
|
3rd Qu.:11.000
|
3rd Qu.:2018
|
NA
|
|
|
Max. :30.000
|
Max. :675.0
|
Max. :299.00
|
NA
|
Max. :31.00
|
Max. :12.000
|
Max. :2018
|
NA
|
|
|
NA
|
NA
|
NA
|
NA
|
NA’s :3828
|
NA’s :3828
|
NA’s :3828
|
NA
|
## individual variables
kable(summary(individual), "html") %>%
kable_paper(bootstrap_options = "striped", full_width = F)
|
|
individualno
|
clusterno
|
householdno
|
sex
|
age
|
weight_kg
|
height_mm
|
education
|
bp_measurement_1_consent
|
bp_measurement_1_systolic
|
bp_measurement_1_diastolic
|
bp_ever_measured
|
bp_ever_diagnosed
|
bp_taking_medicine
|
bp_measurement_2_systolic
|
bp_measurement_2_diastolic
|
bp_measurement_3_systolic
|
bp_measurement_3_diastolic
|
|
|
Min. : 1.000
|
Min. : 1.0
|
Min. : 1.00
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
Length:89819
|
|
|
1st Qu.: 2.000
|
1st Qu.:160.0
|
1st Qu.: 30.00
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
Class :character
|
|
|
Median : 3.000
|
Median :340.0
|
Median : 60.00
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
Mode :character
|
|
|
Mean : 3.288
|
Mean :340.3
|
Mean : 64.27
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
|
|
3rd Qu.: 4.000
|
3rd Qu.:518.0
|
3rd Qu.: 93.00
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
|
|
Max. :30.000
|
Max. :675.0
|
Max. :299.00
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
NA
|
# Change the values of ‘95+’ in variable age to ‘95’
individual$age[individual$age == "95+"] <- "95"
# Convert variables into factor variables
## household
household <- household %>%
mutate(urbanrural = as.factor(urbanrural),
wealthindex = as.factor(wealthindex))
## individual
individual <- individual %>%
mutate(sex = as.factor(sex),
education = as.factor(education))
# Relevel factors
household <- household %>%
mutate(urbanrural = fct_relevel(urbanrural, c("urban", "rural")),
wealthindex = fct_relevel(wealthindex, c("poorest", "poorer", "middle", "richer", "richest")))
individual <- individual %>%
mutate(sex = fct_relevel(sex, c("male", "female")),
education = fct_relevel(education, c("no education", "primary", "secondary", "college or higher")))
# Convert variables into numeric variables
individual <- individual %>%
mutate(age = as.numeric(age),
weight_kg = as.numeric(weight_kg),
height_mm = as.numeric(height_mm),
bp_measurement_1_systolic = as.numeric(bp_measurement_1_systolic),
bp_measurement_1_diastolic = as.numeric(bp_measurement_1_diastolic),
bp_measurement_2_systolic = as.numeric(bp_measurement_2_systolic),
bp_measurement_2_diastolic = as.numeric(bp_measurement_2_diastolic),
bp_measurement_3_diastolic = as.numeric(bp_measurement_3_diastolic),
bp_measurement_3_systolic = as.numeric(bp_measurement_3_systolic))
## Warning: There were 8 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `weight_kg = as.numeric(weight_kg)`.
## Caused by warning:
## ! NAs introduced by coercion
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 7 remaining warnings.
# Create unique identifier for individuals
individual$cluster_household_indiv_unique_id <- paste(individual$clusterno, individual$householdno, individual$individualno, sep = "_")
household$cluster_household_indiv_unique_id <- paste(household$clusterno, household$householdno, household$individualno, sep = "_")
# Create unique identifier for households
household$cluster_household_unique_id <- paste(household$clusterno, household$householdno, sep = "_")
individual$cluster_household_unique_id <- paste(individual$clusterno, individual$householdno, sep = "_")
# Calculate the number of unique clusters, households and individuals in both datasets
unique_clusters_household <- length(unique(household$clusterno))
unique_clusters_individual <- length(unique(individual$clusterno))
unique_households_household <- length(unique(household$householdno))
unique_households_individual <- length(unique(individual$householdno))
unique_individuals_household <- length(unique(household$individualno))
unique_individuals_individual <- length(unique(individual$individualno))
Task 3. Merge the datasets
- We wish to create a single data frame with the information from the
household and individual datasets. Merge the household dataset and
individual dataset by the unique identifier for individuals you created
from Task 2; and name the new dataset ‘bangladesh’
bangladesh <- merge(household, individual, by.x = "cluster_household_indiv_unique_id", by.y = "cluster_household_indiv_unique_id", all = TRUE)
Task 4. Select and remove rows based on conditions
- Select the individuals who have granted consent to the interview,
name the new dataset ‘bangladesh_cs’
- Get an overview of the missing values in age, weight, height and all
the blood pressure measurement variables, and present the number of
missing values for each of these variables in a single data frame
- Remove all the rows with NAs in BP measurements and in age, and name
the new dataset ‘bangladesh_cs_nm’
- Check out the number of unique households and individuals in dataset
‘bangladesh_cs_nm’.
# Add your codes (Please use #comments to organize codes)
# Individuals who have granted consent
bangladesh_cs <- bangladesh %>% filter(str_detect(bp_measurement_1_consent, "granted"))
# Overview of the missing values
missing_age <- c((sum(is.na(bangladesh_cs$age))))
missing_weight<- c((sum(is.na(bangladesh_cs$weight))))
missing_height <- c((sum(is.na(bangladesh_cs$height))))
missing_bp_measurement_1_systolic <- c((sum(is.na(bangladesh_cs$bp_measurement_1_systolic))))
missing_bp_measurement_1_diastolic <- c((sum(is.na(bangladesh_cs$bp_measurement_1_diastolic))))
missing_bp_measurement_2_systolic <- c((sum(is.na(bangladesh_cs$bp_measurement_2_systolic))))
missing_bp_measurement_2_diastolic <- c((sum(is.na(bangladesh_cs$bp_measurement_2_diastolic))))
missing_bp_measurement_3_systolic <- c((sum(is.na(bangladesh_cs$bp_measurement_3_systolic))))
missing_bp_measurement_3_diastolic <- c((sum(is.na(bangladesh_cs$bp_measurement_3_diastolic))))
missing_values_bangladesh <- data.frame(missing_age,
missing_weight,
missing_height,
missing_bp_measurement_1_systolic,
missing_bp_measurement_1_diastolic,
missing_bp_measurement_2_diastolic,
missing_bp_measurement_2_systolic,
missing_bp_measurement_3_diastolic,
missing_bp_measurement_3_systolic)
# Remove all the rows with NAs
bangladesh_cs_nm <- bangladesh_cs %>%
drop_na(age, bp_measurement_1_diastolic, bp_measurement_1_systolic, bp_measurement_2_diastolic, bp_measurement_2_systolic, bp_measurement_3_diastolic, bp_measurement_3_systolic)
# Number of unique households and individuals
unique_households_no <- length(unique(bangladesh_cs_nm$cluster_household_indiv_unique_id))
unique_individuals_no <- length(unique(bangladesh_cs_nm$cluster_household_unique_id))
Task 5. Create new variables based on conditions
- Check out the distribution of variable age in bangladesh_cs_nm, and
create a new variable of age category of 18–34, 35–39, 40–44, 45–49,
50–54, 55–59, 60–64, and ≥65 years
- Create a new variable of BMI
- Body mass index (BMI) is a person’s weight in kilograms divided by
the square of height in meters, BMI = weight (kg) / [height (m)]2
- Check out the mean and the distribution of the new variable BMI
- Create new variables for individual BP
- Check out in the paper how individual BP is defined and create a new
variable for individual BP accordingly
- Create a new variable for the definition of hypertension
- Check out in the paper how ‘hypertensive’ is defined and create a
new variable accordingly
- After creating the variable (hypertension: 1/0), check out the
prevalence of hypertension
- Create a new variable for the awareness of hypertension
- Check out in the paper how ‘awareness of hypertension’ is defined
and create a new variable accordingly
- After creating the variable (awareness: 1/0), check out the
percentage of the people with awareness of hypertension
- Create a new variable for the treatment of hypertension
- Check out in the paper how ‘treatment of hypertension’ is defined
and create a new variable accordingly
- After creating the variable (treatment: 1/0), check out the
percentage of the people with treatment of hypertension
- Create a new variable for the control of hypertension (Control of
hypertension was defined as having an aver- age SBP below 140 mmHg and
DBP below 90 mmHg among those were receiving antihypertensive
medication. )
- Check out in the paper how ‘control of hypertension’ is defined and
create a new variable accordingly
- After creating the variable (control: 1/0), check out the percentage
of the people with control of hypertension
# Add your codes (Please use #comments to organize codes)
# distribution of variable age
bangladesh_cs_nm <- bangladesh_cs_nm %>%
mutate(age_category = case_when(
age >= 18 & age <= 34 ~ "18–34",
age >= 35 & age <= 39 ~ "35–39",
age >= 40 & age <= 44 ~ "40–44",
age >= 45 & age <= 49 ~ "45–49",
age >= 50 & age <= 54 ~ "50–54",
age >= 55 & age <= 59 ~ "55–59",
age >= 60 & age <= 64 ~ "60–64",
age >= 65 ~ "≥65"))
# new variable of bmi
bangladesh_cs_nm <- bangladesh_cs_nm %>%
mutate(BMI = weight_kg / (height_mm*0.001)^2)
summary(bangladesh_cs_nm$BMI)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 11.64 19.38 21.93 22.39 24.93 71.79 139
hist(bangladesh_cs_nm$BMI, main = "Distribution of BMI", xlab = "BMI")

# new variable for individual BP
bangladesh_cs_nm <- bangladesh_cs_nm %>%
rowwise() %>%
mutate(
bp_measurement_individual_systolic = (bp_measurement_2_systolic + bp_measurement_3_systolic) / 2,
bp_measurement_individual_diastolic = (bp_measurement_2_diastolic + bp_measurement_3_diastolic) / 2)
# new variable for hypertension
bangladesh_cs_nm <- bangladesh_cs_nm %>%
mutate(
hypertension = as.integer(
bp_measurement_individual_systolic >= 140,
bp_measurement_individual_diastolic >= 90,
bp_taking_medicine == "yes"))
# prevalence of hypertension
prevalence_hypertension <- (sum(bangladesh_cs_nm$hypertension == 1) / nrow(bangladesh_cs_nm)) * 100
# new variable for awareness of hypertension
bangladesh_cs_nm <- bangladesh_cs_nm %>%
mutate(
awareness_hypertension = as.integer(bp_ever_diagnosed == "yes"))
# percentage of people aware of hypertension
awareness_counts <- table(bangladesh_cs_nm$awareness_hypertension)
total_count_awareness <- sum(awareness_counts)
awareness_percentage <- (awareness_counts/total_count_awareness) * 100
result_awareness_percentage <- data.frame(
awaness_hypertension = names (awareness_percentage),
Percentage = awareness_percentage
)
# new variable for treatment of hypertension
bangladesh_cs_nm <- bangladesh_cs_nm %>%
mutate(
taking_medicine_hypertension = as.integer(bp_taking_medicine == "yes"))
# percentage of people doing treatment
treatment_hypertension_counts <- table(bangladesh_cs_nm$taking_medicine_hypertension)
total_count_treatment <- sum(treatment_hypertension_counts)
treatment_hypertension_percentage <- (treatment_hypertension_counts/total_count_treatment) * 100
# control of hypertension
bangladesh_cs_nm <- bangladesh_cs_nm %>%
mutate(
control_hypertension = as.integer(
bp_measurement_individual_systolic <= 140,
bp_measurement_individual_diastolic <= 90,
bp_taking_medicine == "yes"
))
# Percentage control of hypertension
control_hypertension_counts <- table(bangladesh_cs_nm$control_hypertension)
total_count_control_hypertension <- sum(control_hypertension_counts)
control_hypertension_percentage <- (control_hypertension_counts/total_count_control_hypertension) * 100
Task 6. Regression model
- Fit a logistic regression model with the hypertension variable as
dependent variable and age, gender, education level, wealthindex and BMI
as independent variables
- Call this model logit_hypertension
- Output the results of logit_hypertension
# Add your codes (Please use #comments to organize codes)
# logistic regression model
logit_hypertension <- glm(hypertension ~ age + sex + education + wealthindex + BMI,
data = bangladesh_cs_nm,
family = binomial)
# output the results
summary(logit_hypertension)
##
## Call:
## glm(formula = hypertension ~ age + sex + education + wealthindex +
## BMI, family = binomial, data = bangladesh_cs_nm)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -7.037590 0.206194 -34.131 <2e-16 ***
## age 0.071263 0.001919 37.141 <2e-16 ***
## sexfemale 0.074140 0.056989 1.301 0.193
## educationprimary 0.021165 0.069322 0.305 0.760
## educationsecondary 0.006061 0.082680 0.073 0.942
## educationcollege or higher 0.020370 0.106493 0.191 0.848
## wealthindexpoorer 0.140844 0.088817 1.586 0.113
## wealthindexmiddle 0.052211 0.089543 0.583 0.560
## wealthindexricher 0.092283 0.091903 1.004 0.315
## wealthindexrichest 0.052857 0.095303 0.555 0.579
## BMI 0.089443 0.006975 12.824 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 11221.7 on 12759 degrees of freedom
## Residual deviance: 9084.2 on 12749 degrees of freedom
## (139 observations deleted due to missingness)
## AIC: 9106.2
##
## Number of Fisher Scoring iterations: 5
Task 7. Reporting and Data visualization 1
- Create a table and figure similar to Table 2 and
Figure 3 of the paper:
- Calculate the crude prevalence of (A) hypertension, (B) awareness,
(C) treatment, and (D) control, stratified by age categories and sex;
and put the numbers into a table with the same structure as Table 2 in
the paper (table should be formatted in R Markdown)
- Generate a graph similar to Figure 3 in the paper using the crude
prevalence you just calculated
## table 2
### calculating crude prevalence
# hypertension
crude_prevalence_hypertension <- bangladesh_cs_nm %>%
group_by(age_category, sex) %>%
summarize(crude_prevalence_hypertension = (sum(hypertension == 1) / n()) * 100)
# awareness
crude_prevalence_awareness <- bangladesh_cs_nm %>%
group_by(age_category, sex) %>%
summarize(crude_prevalence_awareness = (sum(awareness_hypertension == 1) / n()) * 100)
# Treatment
crude_prevalence_taking_medicine <- bangladesh_cs_nm %>%
group_by(age_category, sex) %>%
summarize(crude_prevalence_taking_medicine = (sum(taking_medicine_hypertension == 1) / n()) * 100)
# Control
crude_prevalence_control_hypertension <- bangladesh_cs_nm %>%
group_by(age_category, sex) %>%
summarize(crude_prevalence_control_hypertension = (sum(control_hypertension == 1) / n()) * 100)
bangladesh_cs_nm <- left_join(bangladesh_cs_nm, crude_prevalence_hypertension, by = c("age_category", "sex"))
bangladesh_cs_nm <- left_join(bangladesh_cs_nm, crude_prevalence_awareness, by = c("age_category", "sex"))
bangladesh_cs_nm <- left_join(bangladesh_cs_nm, crude_prevalence_taking_medicine, by = c("age_category", "sex"))
bangladesh_cs_nm <- left_join(bangladesh_cs_nm, crude_prevalence_control_hypertension, by = c("age_category", "sex"))
# stratifying by age
stratified_data_table_age <- bangladesh_cs_nm %>%
group_by(age_category) %>%
summarize(
crude_prevalence_hypertension = (sum(hypertension == 1) / n()) * 100,
crude_prevalence_awareness = (sum(awareness_hypertension == 1) / n()) * 100,
crude_prevalence_taking_medicine = (sum(taking_medicine_hypertension == 1) / n()) * 100,
crude_prevalence_control_hypertension = (sum(control_hypertension == 1) / n()) * 100)
# stratifying by sex
stratified_data_table_sex <- bangladesh_cs_nm %>%
group_by(sex) %>%
summarize(
crude_prevalence_hypertension = (sum(hypertension == 1) / n()) * 100,
crude_prevalence_awareness = (sum(awareness_hypertension == 1) / n()) * 100,
crude_prevalence_taking_medicine = (sum(taking_medicine_hypertension == 1) / n()) * 100,
crude_prevalence_control_hypertension = (sum(control_hypertension == 1) / n()) * 100)
# age table
table_age <- kable(
stratified_data_table_age,
format = "markdown",
caption = "Crude Prevalence by Age Category",
col.names = c("Age Category", "Hypertension", "Awareness", "Taking Medicine", "Control"),
align = c("l", "c", "c", "c", "c"),
digits = 2
) %>%
kable_styling("striped", full_width = FALSE)
# sex table
table_sex <- kable(
stratified_data_table_sex,
format = "markdown",
caption = "Crude Prevalence by Sex",
col.names = c("Sex", "Hypertension", "Awareness", "Taking Medicine", "Control"),
align = c("l", "c", "c", "c", "c"),
digits = 2
) %>%
kable_styling("striped", full_width = FALSE)
### putting the age in the right order ###
age_order <- c("18–34", "35–39", "40–44", "45–49", "50–54", "55–59", "60–64", "≥65")
bangladesh_cs_nm$age_category <- factor(bangladesh_cs_nm$age_category, levels = age_order)
#### creating graphs similar to figure 3 ####
## hypertension graph ##
ggplot(bangladesh_cs_nm, aes(x = age_category, y = crude_prevalence_hypertension, fill = sex)) +
geom_bar(position = "dodge", stat = "identity", color = "gray", width = 0.7) +
labs(title = "Hypertension",
x = "Age Category",
y = "Hypertension Prevalence (%)",
fill = "Sex") +
theme_minimal()

ggplot(bangladesh_cs_nm, aes(x = age_category, y = crude_prevalence_awareness, fill = sex)) +
geom_bar(position = "dodge", stat = "identity", color = "gray", width = 0.7) +
labs(title = "Awareness",
x = "Age Category",
y = "Hypertension Prevalence (%)",
fill = "Sex") +
theme_minimal()

ggplot(bangladesh_cs_nm, aes(x = age_category, y = crude_prevalence_taking_medicine, fill = sex)) +
geom_bar(position = "dodge", stat = "identity", color = "gray", width = 0.7) +
labs(title = "Treatment",
x = "Age Category",
y = "Hypertension Prevalence (%)",
fill = "Sex") +
theme_minimal()

ggplot(bangladesh_cs_nm, aes(x = age_category, y = crude_prevalence_control_hypertension, fill = sex)) +
geom_bar(position = "dodge", stat = "identity", color = "gray", width = 0.7) +
labs(title = "Control",
x = "Age Category",
y = "Hypertension Prevalence (%)",
fill = "Sex") +
theme_minimal()

Task 8. Data visualization 2
- Make a scatter plot of BMI and systolic BP with a regression line
- Use ggplot and customize your graph with some additional features,
e.g. adding a title/axis label/vertical line
# Add your codes (Please use #comments to organize codes)
bangladesh_cs_nm <- na.omit(bangladesh_cs_nm)
scatterdata <- bangladesh_cs_nm %>%
filter(BMI <= 50)
ggplot(scatterdata, aes(x = BMI , y= bp_measurement_individual_systolic, color = sex)) +
geom_point(size=0.5)+
labs(title = "Scatter Plot Visualization",
x = "BMI",
y = "Systolic BP")+
geom_smooth(method="lm", color = "black", linetype = "dashed") +
geom_vline(xintercept = 25, linetype = "dashed", color = "red") +
theme_minimal()
