specify also an aspect ratio for the second plot and use patchwork
library(dplyr)
library(ggplot2)
library(tidyr)
library(cowplot)
library(tibble)
library(patchwork)
Dataset.
mtcars %>%
select(1: 7) %>%
cor() %>%
round(., 1)-> m
label <- colnames(m)
heatmap
m %>%
as.data.frame() %>%
tibble() %>%
mutate(id=label) %>%
gather(key=y, value=value, -id) %>%
rename(x=id) %>%
ggplot(aes(x=ordered(x,levels=label), y=ordered(y,levels=rev(label)), fill=value)) +
geom_tile() +
geom_text(aes(label=value), size=4) +
scale_fill_viridis_c() +
coord_fixed() -> g
another value
data.frame(value=apply(m*100, 1, mean)) %>%
rownames_to_column() %>%
rename(y=rowname) %>%
mutate(another_value=round(value, 1)) %>%
ggplot(aes(x=1, y=ordered(y,levels=rev(label)), fill=another_value)) +
geom_tile() +
geom_text(aes(label=another_value), size=4) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank()) +
scale_fill_distiller(palette = 'Spectral')+
theme(aspect.ratio = 8)-> gg
g + gg