Scientific Visualization with Grafify: Comprehensive Guide
Color-blind friendly plots for clinical research and experimental data
ClinicoPath
2025-07-13
Source:vignettes/jjstatsplot-15-grafify-comprehensive.Rmd
jjstatsplot-15-grafify-comprehensive.Rmd
Introduction to Grafify Scientific Plots
The grafify
function in ClinicoPath provides access to
the powerful grafify R package for creating beautiful, color-blind
friendly scientific visualizations. This module is specifically designed
for clinical research, experimental data analysis, and scientific
publications.
Key Features
- 12+ Color-blind friendly palettes optimized for scientific visualization
- Multiple plot types including scatter plots, box plots, violin plots, and specialized designs
- Integrated statistical analysis with ANOVA, t-tests, correlations, and post-hoc comparisons
- Experimental design support for randomized blocks, repeated measures, and factorial designs
- Before-after analysis for paired data and longitudinal studies
- Publication-ready styling with professional themes and customization options
Accessing Grafify in jamovi
The grafify functionality is available through the jamovi interface:
- Load your data into jamovi
- Navigate to Analyses → ClinicoPath → JJ Plots → Grafify
- Select variables for your analysis
- Choose plot type from the available options
- Customize colors, themes, and statistical options
- Export high-resolution plots for publication
Available Plot Types
Basic Plot Types
The grafify module supports these core visualization types:
- scatterbar: Scatter plots with summary statistics and error bars
- scatterbox: Box plots with individual data points overlaid
- scatterviolin: Violin plots showing data distribution and points
- histogram: Distribution histograms with grouping options
- density: Density plots for continuous data visualization
Color Palettes
Grafify includes scientifically optimized, color-blind friendly palettes:
- default: Standard palette for general use
- vibrant: High-contrast colors for presentations
- contrast: Maximum contrast for accessibility
- bright: Bright colors for highlighting
- muted: Subtle colors for professional publications
- dark: Dark theme compatible colors
Example Data Setup
# Create example clinical trial data
set.seed(123)
clinical_data <- data.frame(
patient_id = 1:120,
treatment = rep(c("Control", "Drug A", "Drug B"), each = 40),
age_group = rep(c("Young", "Middle", "Senior"), times = 40),
gender = rep(c("Male", "Female"), times = 60),
biomarker_baseline = rnorm(120, mean = 10, sd = 3),
biomarker_followup = rnorm(120, mean = 12, sd = 4),
response_score = rnorm(120, mean = 75, sd = 15),
timepoint = rep(c("Baseline", "Follow-up"), each = 60)
)
# Display data structure
str(clinical_data)
head(clinical_data)
Example Visualizations
Here are examples of the types of plots you can create with grafify in jamovi:
Scatter Plot with Error Bars
# This demonstrates the type of plot grafify creates with scatterbar
summary_data <- clinical_data %>%
group_by(treatment) %>%
summarise(
mean_biomarker = mean(biomarker_baseline, na.rm = TRUE),
sd_biomarker = sd(biomarker_baseline, na.rm = TRUE),
.groups = 'drop'
)
ggplot(clinical_data, aes(x = treatment, y = biomarker_baseline, color = treatment)) +
geom_point(position = position_jitter(width = 0.2), alpha = 0.7, size = 2) +
geom_point(data = summary_data, aes(y = mean_biomarker), size = 4) +
geom_errorbar(data = summary_data,
aes(y = mean_biomarker,
ymin = mean_biomarker - sd_biomarker,
ymax = mean_biomarker + sd_biomarker),
width = 0.2, size = 1) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73")) +
theme_minimal() +
labs(title = "Biomarker Levels by Treatment Group",
subtitle = "Points show individual values, error bars show standard deviation",
y = "Biomarker Level (Baseline)", x = "Treatment Group") +
theme(legend.position = "none")
Box Plot with Individual Points
ggplot(clinical_data, aes(x = treatment, y = response_score, color = gender)) +
geom_boxplot(alpha = 0.7, outlier.shape = NA, position = position_dodge(width = 0.8)) +
geom_point(position = position_jitterdodge(dodge.width = 0.8, jitter.width = 0.2),
alpha = 0.6, size = 1.5) +
scale_color_manual(values = c("#E69F00", "#56B4E9")) +
theme_minimal() +
labs(title = "Response Scores by Treatment and Gender",
subtitle = "Box plots with individual data points overlaid",
y = "Response Score", x = "Treatment Group", color = "Gender") +
theme(legend.position = "top")
Before-After Comparison
# Reshape data for before-after comparison
before_after_data <- data.frame(
patient_id = rep(1:60, 2),
treatment = rep(rep(c("Control", "Drug A", "Drug B"), each = 20), 2),
timepoint = rep(c("Baseline", "Follow-up"), each = 60),
biomarker = c(clinical_data$biomarker_baseline[1:60],
clinical_data$biomarker_followup[1:60])
)
ggplot(before_after_data, aes(x = timepoint, y = biomarker, color = treatment)) +
geom_line(aes(group = patient_id), alpha = 0.3) +
geom_point(alpha = 0.7, size = 2) +
stat_summary(fun = mean, geom = "point", size = 4, shape = 15) +
stat_summary(fun = mean, geom = "line", aes(group = treatment), size = 1.5) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73")) +
theme_minimal() +
labs(title = "Biomarker Changes: Baseline to Follow-up",
subtitle = "Individual patient trajectories with group means",
y = "Biomarker Level", x = "Time Point", color = "Treatment") +
theme(legend.position = "top")
Statistical Analysis Integration
Grafify integrates with statistical analysis options:
Clinical Research Applications
Best Practices
Data Preparation
- Clean your data before analysis
- Check for outliers and missing values
- Ensure proper factor levels for grouping variables
- Consider transformations for skewed data
Troubleshooting
Conclusion
The grafify module in ClinicoPath provides powerful, accessible tools for scientific visualization. Its integration with jamovi makes advanced plotting techniques available to researchers without programming experience, while maintaining the flexibility and quality needed for professional scientific publication.
By combining color-blind friendly design, statistical integration, and publication-ready output, grafify serves as a comprehensive solution for clinical and experimental data visualization needs.