Code
library(data.table)
library(reactable)
<- fread("../inst/data/bubble_plot.txt")
df
reactable(
df, defaultPageSize = 5,
theme = reactableTheme(
backgroundColor = "transparent"
) )
A bubble plot is essentially a scatterplot where a third numeric variable determines the size of the circles.
A scatterplot illustrates the relationship between two numeric variables. Each dot represents an observation, with its position on the X (horizontal) and Y (vertical) axes indicating the values of the two variables.
This is an example of a data format containing the necessary information for bubble plot visualizations. The table includes mock data specifically generated for this purpose.
The ggplot2
package enables the creation of bubble charts using the geom_point()
function.
This plot contains different pathways. The size of the bubble depends on the count and the color of the bubble depends on the -log(p.adj).
# libraries -------
library(ggplot2)
ggplot(data = df) +
geom_point(
aes(x = NES, y = Description,
size = `Count`,
fill = log_padj
),
shape = 21, stroke = .25
) +
scale_size_continuous(range = c(2, 7)) +
scale_fill_gradient(
low = "grey", high = "#f30000",
guide = guide_colorbar(
title = "-log10(p.adj)",
barheight = unit(10, "lines"),
barwidth = unit(.75, "lines")
)
) +
theme_minimal() +
theme(
axis.title.y = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(linewidth = .4),
panel.border = element_rect(fill = NA, linewidth = .4),
axis.ticks = element_line(linewidth = .4),
plot.margin = margin(20, 20, 20, 20)
) +
facet_grid(
rows = vars(Group),
scales = "free_y",
space = "free_y")