Code
library(ggplot2)
library(gtsummary)
Install packages (if required) and then load them
Basic Syntax
Histograms
#dots slightly bigger, the dots have a red outline and green fill, make the line of best fit purple and panel by the variable stage and centre the title
ggplot(trial, aes(x = age, y = marker)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
ggtitle("Scatter Plot of Age vs Marker") +
xlab("Age") +
ylab("Marker")
ggplot(trial, aes(x = age, y = marker)) +
geom_point(size = 3, shape = 21, color = "red", fill = "green") + # larger dots with red outline and green fill
geom_smooth(method = "lm", se = FALSE, color = "purple") + # line of best fit in purple
facet_wrap(~ stage) + # panel by the variable stage
ggtitle("Scatter Plot of Age vs Marker") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # center and bold the title
axis.title = element_text(size = 12), # increase axis title size
axis.text = element_text(size = 10), # increase axis text size
strip.text = element_text(size = 12) # increase facet strip text size
) +
xlab("Age") +
ylab("Marker")
#Publication quality and greyscale
ggplot(trial, aes(x = age, y = marker)) +
geom_point(size = 3, shape = 21, color = "black", fill = "grey70") + # larger dots with black outline and grey fill
geom_smooth(method = "lm", se = FALSE, color = "black") + # line of best fit in black
facet_wrap(~ stage) + # panel by the variable stage
ggtitle("Scatter Plot of Age vs Marker") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # center and bold the title
axis.title = element_text(size = 12), # increase axis title size
axis.text = element_text(size = 10), # increase axis text size
strip.text = element_text(size = 12) # increase facet strip text size
) +
xlab("Age") +
ylab("Marker")
library(ggridges)
library(viridis)
ggplot(trial, aes(x = marker, y = stage, fill = ..x..)) +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
scale_fill_viridis(name = "Marker", option = "magma") + # using the magma color palette
theme_minimal() +
labs(
x = "Marker",
y = "Stage",
title = "Density Plot of Marker by Stage"
) +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # center and bold the title
axis.title = element_text(size = 12), # increase axis title size
axis.text = element_text(size = 10), # increase axis text size
strip.text = element_text(size = 12) # increase facet strip text size
)