廿TT

譬如水怙牛過窓櫺 頭角四蹄都過了 因甚麼尾巴過不得

ggplot2とpatchworkでヒートマップの周辺度数をプロット

今日の川柳

パッチワークパッケージ(GitHub - thomasp85/patchwork: The Composer of ggplots)は便利ですね。

f:id:abrahamcow:20181108211410p:plain

library(tidyverse)
library(patchwork)

data("author",package = "ca")
author_t <- as_data_frame(author) %>% 
  mutate(title=rownames(author)) %>% 
  gather(alphabet,count,-title)

alphabet_t <- group_by(author_t,alphabet) %>% 
  summarise(count=sum(count))

p1<-ggplot(author_t,aes(x=title,y=alphabet,fill=count))+
  geom_tile()+
  scale_fill_continuous(low="white",high="black")+
  theme(legend.position = "left",axis.text.x = element_text(angle=90),
        plot.margin= unit(c(1, 0, 1, 1), "lines"))

p2 <-ggplot(alphabet_t,aes(x=alphabet,y=count))+
  geom_col(fill="white",colour="black")+
  coord_flip()+
  theme(axis.text.y = element_blank(),axis.ticks.y = element_blank(),
        plot.margin= unit(c(1, 1, 1, -1), "lines"))+
  xlab("")

(p1|p2)

参考:ggplot2とpatchworkで周辺分布 | Atusy's blog