r创建颜色条以将yaxis标记为组

问题描述 投票:0回答:1

我正在绘制热图,并希望按颜色在组中标记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))

enter image description here

有办法吗?

此示例的信用和代码转到[https://www.r-graph-gallery.com/79-levelplot-with-ggplot2.html][2]

r ggplot2 colors axis
1个回答
1
投票

您可以单独构建一个“栏”,并用它来注释您的图形。

© www.soinside.com 2019 - 2024. All rights reserved.