1 Star 1 Fork 1

LuWinter/R-for-Data-Science

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Chapter 21.R 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
LuWinter 提交于 2020-07-27 01:06 . R数据科学
library(tidyverse)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_smooth(se = FALSE) +
labs(
title = paste(
"Fuel efficiency generally decreases with",
"engine size"
)
)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_smooth(se = FALSE) +
labs(
title = paste(
"Fuel efficiency generally decreases with",
"energine size"
),
subtitle = paste(
"Two seaters (sports cars) are an exception",
"because of their light weight"
),
caption = "Data from fueleconomy.gov",
x = "Engine displacement (L)",
y = "Highway fuel economy (mpg)",
color = "Car type"
)
df <- tibble(
x = runif(10),
y = runif(10)
)
ggplot(df, aes(x, y)) +
geom_point() +
labs(
x = quote(sum(x[i] ^ 2, i == 1, n)),
y = quote(alpha + beta + frac(delta, theta))
)
best_in_class <- mpg %>%
group_by(class) %>%
filter(row_number(desc(hwy)) == 1)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_text(aes(label = model), data = best_in_class)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_label(
aes(label = model),
data = best_in_class,
nudge_y = 2,
alpha = 0.5
)
ggplot(mpg, aes(displ, hwy)) +
geom_hline(aes(yintercept = 20, size = 2, color = "white")) +
geom_point(aes(color = class)) +
geom_point(size = 3, shape = 1, data = best_in_class) +
ggrepel::geom_label_repel(
aes(label = model),
data = best_in_class,
alpha = 0.5
)
class_avg <- mpg %>%
group_by(class) %>%
summarise(
displ = median(displ),
hwy = median(hwy)
)
ggplot(mpg, aes(displ, hwy, color = class)) +
geom_hline(aes(yintercept = 20, size = 2, color = "#FFFFFF")) +
geom_point(aes(color = class)) +
geom_point(size = 3, shape = 1, data = class_avg) +
ggrepel::geom_label_repel(aes(label = class),
data = class_avg,
size = 4,
alpha = 0.7,
label.size = 0,
segment.color = NA) +
geom_point() +
theme(legend.position = "none")
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
scale_y_continuous(breaks = seq(15, 40, by = 5))
presidential %>%
mutate(id = 33 + row_number()) %>%
ggplot(aes(start, id)) +
geom_point() +
geom_segment(aes(xend = end, yend = id)) +
scale_x_date(
NULL,
breaks = presidential$start,
date_labels = "'%y"
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
R
1
https://gitee.com/luwinter/R-for-Data-Science.git
git@gitee.com:luwinter/R-for-Data-Science.git
luwinter
R-for-Data-Science
R-for-Data-Science
master

搜索帮助