我正在尝试使用颜色条两侧带有两个刻度(或两组标签)的颜色条制作 ggplot2(例如,在颜色指南的左侧和右侧同时具有厘米和英寸刻度bar 或有摄氏度和华氏度)。在 ggplot2 中可能有这样的事情吗?请参阅图片以了解我要查找的内容(理想情况下,在这个小示例中,条形底部的数字为 1:5,条形顶部的字母 a:e)。我可以制作两个传奇并以某种方式叠加它们吗?在顶部和底部有一个标题也会有帮助
df <- tibble(A = letters[1:5], B = 1:5)
ggplot(df, aes(x = A, y = B, fill = B)) +
geom_col() +
scale_fill_gradient(high = "blue", low = "red",
labels = letters[1:5],
guide = guide_colorbar(
direction = "horizontal",
title.position = 'top',
title.hjust = 0.5,
label.hjust = 0.5,
legend.location = "bottom",
label.position = "top")
) +
theme(legend.position = "bottom")