Skip to content

Commit

Permalink
add R visulization
Browse files Browse the repository at this point in the history
  • Loading branch information
Hua Zou committed Aug 30, 2019
1 parent 7e2b41a commit 59d0fc9
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion _posts/2019-08-29-Program-R9.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ packagename(包名字)
|--vignettes/(存放包说明文档目录)
```

<!-- more -->


### 准备工作

Expand Down
76 changes: 76 additions & 0 deletions _posts/2019-08-30-Program-R10.md
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)
Binary file added _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.
Binary file added _posts/img/R10.scatterplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59d0fc9

Please sign in to comment.