jamesbang

V1

2022/12/26阅读：21主题：雁栖湖

# 🧐 ggokabeito | 一般般啵~支持ggplot2和ggraph的配色包！~

## 2用到的包

``rm(list = ls())#devtools::install_github("malcolmbarrett/ggokabeito")library(tidyverse)library(ggokabeito)library(igraph)library(ggraph)library(tidygraph)``

## 3示例数据一

``dat <- diamondsstr(dat)``

## 4频率直方图

``dat %>% ggplot(aes(color, color = color, fill = color)) +  geom_bar() +  theme_bw()+  scale_fill_okabe_ito(name = "Color", alpha = .8) +  scale_color_okabe_ito(name = "Color")``

## 5散点图

``dat <- dat %>%   group_by(., color) %>%   sample_n(., 100) %>%   ungroup()DT::datatable(dat)``

``dat %>%   ggplot(aes(carat, price, color = color)) +  geom_point() +  theme_bw()+  scale_color_okabe_ito()``

``dat %>%   ggplot(aes(carat, price, color = factor(color))) +  geom_point() +  theme_bw()+  scale_color_okabe_ito(name = "Color", alpha = .9)``

## 6密度图

``dat %>% ggplot(aes(carat, color = color, fill = color)) +  geom_density() +  theme_bw()+  scale_fill_okabe_ito(name = "Color", alpha = .9) +  scale_color_okabe_ito(name = "Color")``

## 7折线图

``dat %>% ggplot(aes(carat, price, color = color, fill = color)) +  geom_line() +  theme_bw()+  scale_fill_okabe_ito(name = "Color", alpha = .8) +  scale_color_okabe_ito(name = "Color")``

## 8拟合曲线

``dat %>%   ggplot(aes(x = depth, y = price, colour = color)) +  geom_point(alpha = 0.7) +  geom_smooth(method = "loess", alpha = 0.05, size = 1, span = 1) +  theme_bw()+  scale_color_okabe_ito(name = "Color")``

## 9网络图

### 9.1 示例数据二

``highschool <- highschool %>%   mutate(., mon = sample(1:9, nrow(.), replace = T))DT::datatable(highschool)``

### 9.2 构建网络文件

``graph <- graph_from_data_frame(highschool)graph``

### 9.3 可视化

`ggokabeito`直接支持`ggraph`，直接叠加`scale_edge_color_okabe_ito`即可。🥳

``ggraph(graph, layout = 'kk') +     geom_edge_link(aes(colour = factor(mon))) +     geom_node_point()+    theme_bw()+    scale_edge_color_okabe_ito()``

📍 往期精彩

##### jamesbang
V1

wx🔍: Grassssss 卷起来了