by Edgar Ruiz 原文链接
ggplot图形的增强包ggforce,实现强调部分数据的功能。
library(tidyverse)
library(ggforce)
library(nycflights13)
p <- airports %>%
filter(lon < 0, tzone != "\\N") %>%
ggplot(aes(lon, lat, color = tzone)) +
geom_point(show.legend = FALSE)
给图上添各种圈
p + geom_mark_rect()

p +
geom_mark_rect(aes(label = tzone))

p +
geom_mark_rect(aes(label = tzone), show.legend = FALSE) +
theme_void()

p +
geom_mark_hull(aes(label = tzone)) +
theme_void()

p +
geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE) +
theme_void()

p +
geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE, expand = unit(3, "mm")) +
theme_void()

p +
geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE, expand = unit(3, "mm")) +
theme_no_axes()

p +
geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE, expand = unit(3, "mm")) +
theme_no_axes() +
facet_zoom(x = tzone == "America/Los_Angeles")

网友评论