-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_visualization.R
66 lines (48 loc) · 1.97 KB
/
data_visualization.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
## Test with Casey's data visualization tutorial
## Anusha Shankar
## April 12, 2016
## "ggplot" means grammar of graphics
## Useful link: http://docs.ggplot2.org/current/
## Packages
library(ggplot2)
library(devtools)
## Setwd and read in file
setwd("C:\\Users\\ANUSHA\\Desktop\\")
test <- read.csv("gapminder-FiveYearData.csv")
## geom_point(alpha=...) controls transparency. Plots lines for each group separately because col=
test_transparent <- ggplot(test, aes(lifeExp, gdpPercap)) +
geom_point(alpha=0.2) + theme_bw()
## scale_y_log10
## Makes an axis log10
## Now plots lines for each group separately because col=continent
## can use scale_y_continuous(trans='log')
## Or... trans = asn, exp, identitiy, log, log10, log2, logit, pow10, probit, recip, reverse, sqrt
test_log_col <- ggplot(test, aes(lifeExp, gdpPercap, col=continent)) +
geom_point(alpha=0.2) + theme_bw() + scale_y_log10() + geom_smooth(method='lm')
## Line plot
test_log_country <- ggplot(test, aes(year, lifeExp, by=country)) +
geom_line() + theme_bw()
test_log_country
## Color lines by country
test_log_country_col <- ggplot(test, aes(year, lifeExp, by=country, col=continent)) +
geom_line() + theme_bw()
test_log_country_col
## Color lines by country, added points
test_log_country_col <- ggplot(test, aes(year, lifeExp, by=country, col=continent)) +
geom_line() + theme_bw() + geom_point()
test_log_country_col
## Boxplot, violin plots
ggplot(test, aes(continent, lifeExp)) +
geom_boxplot()
## Boxplot, violin plots, plotted by country, colored by continent
ggplot(test, aes(country, lifeExp, col=continent)) + theme_classic() +
geom_boxplot() + theme(axis.text.x=element_blank())
## Store basic plot as object and then add on to it
## Emojis
devtools::install_github('dill/emoGG')
library(emoGG)
emoji_search('penguin')
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_emoji(emoji='1f427')
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_emoji(emoji='1f414') + add_emoji('1f426') + theme_bw()