# Load required libraries
library(ggplot2)
library(hexbin)
## Warning: package 'hexbin' was built under R version 4.4.1
# Generate sample data
set.seed(123)
n <- 1000
df <- data.frame(
x = runif(n, 1, 10),
y = runif(n, 1, 10),
value = rnorm(n)
)
# Create hexagonal heatmap with borders and no axes
ggplot(df, aes(x = x, y = y)) +
geom_hex(aes(fill = after_stat(density)), bins = 10, color = "white") +
scale_fill_viridis_c() +
labs(title = "Hexagonal Heatmap (10x10)") +
theme_void() +
theme(
legend.position = "right",
plot.title = element_text(hjust = 0.5, margin = margin(b = 10))
) +
coord_fixed(ratio = 1)

#############################
# Define custom color palette
custom_colors <- c("#E6F3FF", "#BDDEFF", "#94C8FF", "#6BB3FF", "#429EFF", "#1A88FF", "#0072FF", "#005CC7", "#00468F", "#003366")
# Create hexagonal heatmap with custom colors and borders
ggplot(df, aes(x = x, y = y)) +
geom_hex(aes(fill = after_stat(density)), bins = 10, color = "white") +
scale_fill_gradientn(colors = custom_colors) +
labs(title = "Hexagonal Heatmap (10x10)", fill = "Density") +
theme_void() +
theme(
legend.position = "right",
plot.title = element_text(hjust = 0.5, margin = margin(b = 10))
) +
coord_fixed(ratio = 1)

######################################
# Load required libraries
library(ggplot2)
library(hexbin)
# Generate sample data
set.seed(123)
n <- 1000
df <- data.frame(
x = runif(n, 1, 10),
y = runif(n, 1, 10),
value = rnorm(n)
)
# Define a colorful palette
colorful_palette <- c("#FF9999", "#FFCC99", "#FFFF99", "#CCFF99", "#99FF99",
"#99FFCC", "#99FFFF", "#99CCFF", "#9999FF", "#CC99FF")
# Create hexagonal heatmap with colorful palette and borders
ggplot(df, aes(x = x, y = y)) +
geom_hex(aes(fill = after_stat(density)), bins = 10, color = "white") +
scale_fill_gradientn(colors = colorful_palette) +
labs(title = "Colorful Hexagonal Heatmap (10x10)", fill = "Density") +
theme_void() +
theme(
legend.position = "right",
plot.title = element_text(hjust = 0.5, margin = margin(b = 10))
) +
coord_fixed(ratio = 1)

#######################
# Load required libraries
library(ggplot2)
library(hexbin)
# Generate sample data
set.seed(123)
n <- 1000
df <- data.frame(
x = runif(n, 1, 10),
y = runif(n, 1, 10),
value = rnorm(n)
)
# Define a pastel rainbow palette
# Load required libraries
library(ggplot2)
library(hexbin)
# Generate sample data
set.seed(123)
n <- 1000
df <- data.frame(
x = runif(n, 1, 10),
y = runif(n, 1, 10),
value = rnorm(n)
)
# Define a colorful gradient palette
colorful_gradient <- c("#0000FF", "#4B0082", "#8B008B", "#FF1493", "#FF69B4", "#FFB6C1")
# Create hexagonal heatmap with colorful gradient and borders
ggplot(df, aes(x = x, y = y)) +
geom_hex(aes(fill = after_stat(density)), bins = 10, color = "white") +
scale_fill_gradientn(colors = colorful_gradient) +
labs(title = "Colorful Gradient Hexagonal Heatmap (10x10)", fill = "Density") +
theme_void() +
theme(
legend.position = "right",
plot.title = element_text(hjust = 0.5, margin = margin(b = 10))
) +
coord_fixed(ratio = 1)

# Save the plot as TIF
ggsave(paste0("C:\\Users\\xut2\\Desktop\\", Sys.Date(),"-","colorful_gradient_heatmap.tif"), width = 10, height = 8, dpi = 300, compression = "lzw")