绘图技巧数据分析

2019-09-27用ggforce给ggplot图上画圈圈

2019-09-27  本文已影响0人  iColors

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() 

image.png
p + 
  geom_mark_rect(aes(label = tzone)) 
image.png
p + 
  geom_mark_rect(aes(label = tzone), show.legend = FALSE) +
  theme_void() 
image.png
p + 
  geom_mark_hull(aes(label = tzone)) +
  theme_void() 
image.png
p + 
  geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE) +
  theme_void() 
image.png
p + 
  geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE, expand = unit(3, "mm")) +
  theme_void() 
image.png
p + 
  geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE, expand = unit(3, "mm")) +
  theme_no_axes() 
image.png
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")
image.png
上一篇 下一篇

猜你喜欢

热点阅读