-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hua Zou
committed
Aug 30, 2019
1 parent
7e2b41a
commit 59d0fc9
Showing
5 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,7 +230,7 @@ font: | |
# Value is the target link (E.g. GitHub: https://github.com/iissnan) | ||
social: | ||
GitHub: https://github.com/HuaZou | ||
Email: [email protected] | ||
Email: mailto:[email protected] | ||
|
||
|
||
# Social Links Icons | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ packagename(包名字) | |
|--vignettes/(存放包说明文档目录) | ||
``` | ||
|
||
<!-- more --> | ||
|
||
|
||
### 准备工作 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
layout: post | ||
title: "R:可视化基础代码(十)" | ||
date: 2019-08-30 16:36:00 | ||
updated: 2019-08-30 | ||
categories: 编程 | ||
tags: R | ||
--- | ||
|
||
### 图形类型 | ||
|
||
- 散点图 | ||
- 直方图 | ||
- 柱状图 | ||
- 箱线图 | ||
- 面积图 | ||
- 热图 | ||
- 相关图 | ||
- 折线图 | ||
- 韦恩图 | ||
- 火山图 | ||
- 饼图 | ||
|
||
|
||
|
||
#### 散点图 | ||
|
||
```R | ||
library(ggplot2) | ||
library(dplyr) | ||
|
||
dat <- %>% mutate(cyl = factor(cyl)) | ||
ggplot(dat, aes(x = wt, y = mpg, shape = cyl, color = cyl)) + | ||
geom_point(size = 3, alpha = 0.4) + | ||
geom_smooth(method = lm, linetype = "dashed", | ||
color = "darkred", fill = "blue") + | ||
geom_text(aes(label = rownames(dat)), size = 4) + | ||
theme_bw(base_size = 12) + | ||
theme(plot.title = element_text(size = 10, color = "black", face = "bold", hjust = 0.5), | ||
axis.title = element_text(size = 10, color = "black", face = "bold"), | ||
axis.text = element_text(size = 9, color = "black"), | ||
axis.ticks.length = unit(-0.05, "in"), | ||
axis.text.y = element_text(margin = unit(c(0.3, 0.3, | ||
0.3, 0.3), "cm"), size = 9), | ||
axis.text.x = element_blank(), | ||
text = element_text(size = 8, color = "black"), | ||
strip.text = element_text(size = 9, color = "black", face = "bold"), | ||
panel.grid = element_blank()) | ||
``` | ||
|
||
![](https://raw.githubusercontent.com/HuaZou/HuaZou.github.io/master/_posts/img/R10.scatterplot.png) | ||
|
||
#### 直方图 | ||
|
||
```R | ||
library(ggplot2) | ||
|
||
data <- data.frame( | ||
Conpany = c("Apple", "Google", "Facebook", "Amozon", "Tencent"), | ||
Sale2013 = c(5000, 3500, 2300, 2100, 3100), | ||
Sale2014 = c(5050, 3800, 2900, 2500, 3300), | ||
Sale2015 = c(5050, 3800, 2900, 2500, 3300), | ||
Sale2016 = c(5050, 3800, 2900, 2500, 3300)) | ||
mydata <- tidyr::gather(data, Year, Sale, -Conpany) | ||
ggplot(mydata, aes(Conpany, Sale, fill = Year)) + | ||
geom_bar(stat = "identity", position = "dodge") + | ||
guides(fill = guide_legend(title = NULL)) + | ||
ggtitle("The Financial Performance of Five Giant") + | ||
scale_fill_wsj("rgby", "") + | ||
theme_wsj() + | ||
theme( | ||
axis.ticks.length = unit(0.5, "cm"), | ||
axis.title = element_blank())) | ||
``` | ||
|
||
![](https://raw.githubusercontent.com/HuaZou/HuaZou.github.io/master/_posts/img/R10.bar.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.