,可以通过以下步骤实现:
完整的代码如下所示:
# 加载ggplot2库
library(ggplot2)
# 创建示例数据集
data <- data.frame(
Row = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
Column = c("X", "Y", "Z", "X", "Y", "Z", "X", "Y", "Z"),
Value = c(1, 2, 3, 4, 5, 6, 7, 8, 9)
)
# 创建热图
p <- ggplot(data, aes(x = Column, y = Row, fill = Value)) +
geom_tile()
# 添加删除线
p <- p + annotate("text", x = "X", y = "A", label = "X",
fontface = "bold", color = "red",
hjust = 0.5, vjust = 0.5, size = 8, angle = 45)
# 调整图表外观
p <- p + theme(axis.text.x = element_text(angle = 45, hjust = 1),
axis.text.y = element_text(angle = 0, hjust = 1),
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5))
# 显示图表
p
这样,热图中特定单元格上的删除线就会被添加上去了。你可以根据具体需求进一步调整图表的样式和设计。
领取专属 10元无门槛券
手把手带您无忧上云