导读
开始学习拼图。
依赖包
library(ggplot2)
library(aplot)
一、输入数据
sample = paste("sample", seq(1, 10, 1), sep=".")
x = seq(1, 10, 1)
y = seq(2, 20, 2)
df = data.frame(sample, x, y)
二、绘制零件
2.1. 散点图
p <- ggplot(df, aes(x=x, y=y)) +
geom_point(color=df$x) +
theme(panel.grid=element_blank(), panel.background=element_rect(color='black', fill='transparent')) +
labs(x="", y="")
- p
2.2. 箱图
p2 <- ggplot(df, aes(x=x, y=1)) +
geom_boxplot(fill='skyblue', alpha=.5) +
theme_void()
p3 <- ggplot(df, aes(x=1, y=y)) +
geom_boxplot(fill='skyblue', alpha=.5) +
theme_void()
- p2
- p3
2.3. 密度图
p4 <- ggplot(df, aes(x=x)) +
geom_density(fill='red') +
theme_void()
p5 <- ggplot(df, aes(y=y)) +
geom_density(fill='red') +
theme_void()
- p4
- p5
二、散点图+箱图
p %>% insert_top(p2, height=.1) %>% insert_right(p3, width=.1)
三、散点图+密度图
p %>% insert_top(p4, height=.2) %>% insert_right(p5, width=.2)
四、散点图+箱图+密度图
p %>% insert_top(p2, height=.1) %>% insert_right(p5, width=.2)