我正在绘制热图,并希望按颜色在组中标记yaxis:
library(ggplot2)
library(tidyr)
library(tibble)
library(hrbrthemes)
library(dplyr)
# Volcano dataset
#volcano
# Heatmap
df <- volcano %>%
# Data wrangling
as_tibble() %>%
rowid_to_column(var="X") %>%
gather(key="Y", value="Z", -1) %>%
# Change Y to numeric
mutate(Y=as.numeric(gsub("V","",Y))) %>%
mutate(group=rep(1:3,each=1769))
ggplot(df,aes(X, Y, fill= Z)) +
geom_tile() +
theme(legend.position="none") +
scale_y_discrete(expand=c(0, 0)) +
scale_x_continuous(expand = c(0, 0))
有办法吗?
此示例的信用和代码转到[https://www.r-graph-gallery.com/79-levelplot-with-ggplot2.html][2]
您可以单独构建一个“栏”,并用它来注释您的图形。