Recently Published
Plot
# Load ggplot2 for visualization
library(ggplot2)
# Plot blood pressure over time by treatment group
ggplot(longitudinal_data, aes(x = Time, y = Blood_Pressure, color = Treatment)) +
geom_line(aes(group = Patient_ID), alpha = 0.3) + # Individual patient lines
stat_summary(fun = mean, geom = "line", size = 1.2, aes(group = Treatment)) + # Mean line
labs(title = "Blood Pressure over Time by Treatment Group", x = "Time", y = "Blood Pressure") +
theme_minimal()
Plot
# Fit the Kaplan-Meier model, stratifying by 'sex'
> km_fit <- survfit(surv_object ~ Smoking_Status, data = clinical_survival_data)
>
> View(km_fit)
>
> # Plot the Kaplan-Meier survival curve
> ggsurvplot(km_fit, data = clinical_survival_data,
+ pval = TRUE, # Add p-value for log-rank test
+ conf.int = TRUE, # Show confidence intervals
+ xlab = "Time in Days", # Label for x-axis
+ ylab = "Survival Probability", # Label for y-axis
+ legend.title = "Smoking Status", # Title for the legend
+ legend.labs = c("Nonsmoker", "Smoker"), # Labels for each group
+ risk.table = TRUE, # Show risk table below the plot
+ risk.table.height = 0.25, # Adjust the height of the risk table
+ ggtheme = theme_minimal()) # Use a minimal theme
>
>
Plot
# Load ggplot2
library(ggplot2)
# Create a contingency table and convert it to a data frame for ggplot
contingency_table <- table(clinical_data$Smoking_Status, clinical_data$Diabetes)
plot_data <- as.data.frame(contingency_table)
colnames(plot_data) <- c("Smoking_Status", "Diabetes", "Count")
# Plot
ggplot(plot_data, aes(x = Smoking_Status, y = Count, fill = Diabetes)) +
geom_bar(stat = "identity", position = "fill") +
labs(title = "Proportion of Diabetes Status by Smoking Status",
x = "Smoking Status",
y = "Proportion") +
scale_y_continuous(labels = scales::percent) +
theme_minimal() +
theme(legend.position = "top")
Plot
# Create a mosaic plot from the contingency table
mosaicplot(contingency_table, main = "Mosaic Plot of Smoking Status and Diabetes",
xlab = "Smoking Status", ylab = "Diabetes", color = TRUE)
Plot
# Scatter plot with trend line
ggplot(clinical_data, aes(x = Age, y = Cholesterol, color = Smoking_Status)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Age vs Cholesterol with Trend Line",
x = "Age (years)",
y = "Cholesterol (mg/dL)")