-
Notifications
You must be signed in to change notification settings - Fork 0
/
Getting started (1).r
154 lines (103 loc) · 2.55 KB
/
Getting started (1).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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
installed.packages()
# We will be using ggplot, which is in the package ggplot2.
install.packages("ggplot2")
library(ggplot2)
data(package="datasets")
data(package="ggplot2")
?mtcars
data("mtcars")
head(mtcars)
nrow(mtcars)
ncol(mtcars)
rownames(mtcars)
colnames(mtcars)
summary(mtcars)
str(mtcars)
mtcars$hp
mtcars['hp']
mtcars
mtcars$cyl
unique(mtcars$cyl)
class(mtcars$cyl)
df<-mtcars
df
class(mtcars$gear)
df$gear<-as.factor(df$gear)
class(df$gear)
ggplot(mtcars)
ggplot(mtcars, aes(cyl)) + geom_bar()
p<-ggplot(mtcars, aes(cyl))
p<-p+geom_bar()
p
p<-ggplot(mtcars, aes(mpg))
p+geom_bar()
We could make it categorical, by using the as.factor function, but it's still not great!
df<-mtcars
df$mpg<-as.factor(df$mpg)
p<-ggplot(df, aes(mpg))
p+geom_bar()
df<-mtcars
df$mpg<-as.integer(df$mpg)
p<-ggplot(df, aes(mpg))
p+geom_bar()
mtcars$cyl = as.factor(mtcars$cyl)
ggplot(data=mtcars, aes(x=cyl)) +
geom_bar()
ggplot(data=mtcars, aes(cyl)) +
geom_bar() +
coord_polar(theta = "y")
p = ggplot(data=mtcars, aes(x="", fill = cyl)) +
geom_bar()
p
ggplot(data = mtcars) +
geom_bar(mapping = aes(x = cyl, fill = cyl)) +
coord_polar()
ggplot(data = mtcars) +
geom_bar(mapping = aes(x =cyl, fill = cyl), width = 1) +
coord_polar()
ggplot(data = mtcars) +
geom_bar(mapping = aes(x =cyl, fill = cyl), width = 1) +
labs(x=NULL) +
theme(
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank()
) +
coord_polar()
p = ggplot(data=mtcars, aes(x = "", fill = cyl)) +
geom_bar() +
labs(x=NULL) +
theme(
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.background=element_blank()
) +
coord_polar(theta = "y")
p
?ChickWeight
data("ChickWeight")
str(ChickWeight)
head(ChickWeight)
install.packages("sqldf")
library(sqldf)
Mychicks = sqldf("select * from ChickWeight where Chick = 1")
ggplot(data=Mychicks, aes(x=Time, y=weight)) +
geom_line()
installed.packages()
# We will be using ggplot, which is in the package ggplot2.
install.packages("ggplot2")
library(ggplot2)
data(package="datasets")
data(package="ggplot2")
ggplot(data=ChickWeight, aes(x=Diet,y=weight))
+ geom_line()
ggplot(data=ChickWeight, aes(Time)) +
geom_bar() +
coord_polar(theta = "y")
p<-ggplot(ChickWeight, aes(Diet))
p<-p+geom_bar()
p
p = ggplot(data=ChickWeight, aes(x="weight", fill = Diet)) +
geom_bar()
p