扩展笔记 Top50 ggplot2 图库

Scatterplot With Encircling

围绕图形示例、绘制逻辑与适用场景,便于快速迁移到自己的分析任务。

R训练营主题笔记

围绕图形类型整理适用场景、绘图思路与示例代码,便于快速迁移到自己的数据。

相关主题:2.Scatterplot With Encircling ### Scatterplot With Encircling

# install 'ggalt' pkg
# devtools::install_github("hrbrmstr/ggalt")
options(scipen = 999)
library(ggplot2)
library(ggalt)
midwest_select <- midwest[midwest$poptotal > 350000 &
                            midwest$poptotal <= 500000 &
                            midwest$area > 0.01 &
                            midwest$area < 0.1, ]

# Plot
ggplot(midwest, aes(x=area, y=poptotal)) +
  geom_point(aes(col=state, size=popdensity)) +   # draw points
  geom_smooth(method="loess", se=F) +
  xlim(c(0, 0.1)) +
  ylim(c(0, 500000)) +   # draw smoothing line
  geom_encircle(aes(x=area, y=poptotal), #这个函数需要选择我们需要圈出来的数据
                data=midwest_select,
                color="red",
                size=2,
                expand=0.08) +   # encircle
  labs(subtitle="Area Vs Population",
       y="Population",
       x="Area",
       title="Scatterplot + Encircle",
       caption="Source: midwest")
← 返回训练营笔记库 去看单细胞模块 →