ggplot:将网格线与geom_tile的末端对齐

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

我正在尝试使用ggplots geom_tile创建一个热图。就目前而言,网格线位于每个geom_tile的中间。我想要的是将网格线与每个图块的开始/结尾对齐。我看过一些相关的文章(herehere,但所有文章都涉及连续的标尺。就我而言,两个标尺都是离散的/因子。知道吗?非常感谢!

library(tidyverse)

my_iris <- iris %>% 
  mutate(sepal_interval=cut(Sepal.Length, 4)) %>% 
  group_by(sepal_interval, Species)

my_iris %>% 
  summarise(n_obs=n()) %>% 
  ggplot()+
  geom_tile(aes(y=Species,
                x=sepal_interval,
                fill=n_obs))+
  theme_bw()+
  theme(panel.grid = element_line(color="black"))

“”

reprex package(v0.3.0)在2020-01-28创建

r ggplot2
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.