R is a powerful and widely-used programming language and software environment for statistical computing, data analysis, and graphical representation. It was created by statisticians Ross Ihaka and Robert Gentleman in the mid-1990s and has since become one of the most popular tools for data analysis in academia, industry, and government.
Key Features of R
Statistical Analysis:
- R was designed specifically for statistics and data analysis. It has a vast array of statistical techniques, including linear and nonlinear modeling, time-series analysis, classification, clustering, and more.
- It is widely used for conducting hypothesis testing, statistical inference, and regression analysis.
Data Visualization:
- R is known for its powerful data visualization capabilities. The base R system provides a range of plotting functions, but the real power comes from packages like ggplot2, which allow for creating highly customizable and complex visualizations.
- R can produce static graphics, interactive visualizations, and even integrate with web applications.
Extensibility through Packages:
- R has a vast ecosystem of packages (over 18,000 available on CRAN — the Comprehensive R Archive Network) that extend its functionality. These packages cover a wide range of domains, including bioinformatics, econometrics, machine learning, and more.
- Users can easily install and load these packages to add new features to their R environment.
Open-Source:
- R is an open-source language, meaning it is free to use and the source code is available for anyone to inspect, modify, and enhance. This has led to a large, active community that continuously contributes to the language and its ecosystem.
- The open-source nature also allows R to be highly portable, running on various operating systems including Windows, macOS, and Linux.
Data Handling and Storage:
- R excels at handling and manipulating large datasets. It provides various data structures like vectors, matrices, data frames, and lists, which can be used to store and process data efficiently.
- It also integrates well with databases and can handle data from various formats such as CSV, Excel, JSON, and SQL databases.
Integration with Other Languages:
- R can be integrated with other programming languages such as Python, C++, and Java. This allows users to leverage R’s statistical capabilities while also utilizing the strengths of other languages.
- R can also be embedded in web applications and used with tools like R Markdown to create dynamic reports and documents.
Support for Machine Learning:
- R is equipped with numerous machine learning packages and algorithms for tasks such as classification, regression, clustering, and deep learning.
- Packages like caret provide a unified interface for training and evaluating machine learning models, while others like randomForest and xgboost implement specific algorithms.
R language new advance code
install.packages("gcookbook")
Installing package into ‘C:/Users/ADMIN/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/gcookbook_2.0.zip'
Content type 'application/zip' length 4012215 bytes (3.8 MB)
downloaded 3.8 MB
package ‘gcookbook’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\ADMIN\AppData\Local\Temp\RtmpWmK7Tq\downloaded_packages
> library(gcookbook)
Warning message:
package ‘gcookbook’ was built under R version 3.5.2
> library(gcookbook)
> madmen2
Name1 Name2
1 Abe Drexler Peggy Olson
2 Allison Don Draper
3 Arthur Case Betty Draper
4 Bellhop in Baltimore Sal Romano
5 Bethany Van Nuys Don Draper
6 Betty Draper Don Draper
7 Betty Draper Henry Francis
8 Betty Draper Random guy
9 Bobbie Barrett Don Draper
10 Brooklyn College Student Peggy Olson
11 Candace Don Draper
12 Don Draper Allison
13 Don Draper Bethany Van Nuys
14 Don Draper Betty Draper
15 Don Draper Bobbie Barrett
16 Don Draper Candace
17 Don Draper Doris
18 Don Draper Faye Miller
19 Don Draper Joy
20 Don Draper Megan Calvet
21 Don Draper Midge Daniels
22 Don Draper Rachel Menken
23 Don Draper Shelly
24 Don Draper Suzanne Farrell
25 Don Draper Woman at the Clios party
26 Doris Don Draper
27 Duck Phillips Peggy Olson
28 Elliot Sal Romano
29 Faye Miller Don Draper
30 Franklin Joan Holloway
31 Greg Harris Joan Holloway
32 Gudrun Pete Campbell
33 Harry Crane Hildy
34 Harry Crane Jennifer Crane
35 Henry Francis Betty Draper
36 Hildy Harry Crane
37 Ida Blankenship Roger Sterling
38 Jane Siegel Roger Sterling
39 Janine Lane Pryce
40 Jennifer Crane Harry Crane
41 Joan Holloway Franklin
42 Joan Holloway Greg Harris
43 Joan Holloway Roger Sterling
44 Joy Don Draper
45 Joyce Ramsay Peggy Olson
46 Kitty Romano Sal Romano
47 Lane Pryce Janine
48 Lane Pryce Rebecca Pryce
49 Lane Pryce Toni
50 Lee Garner Jr. Sal Romano
51 Mark Peggy Olson
52 Megan Calvet Don Draper
53 Midge Daniels Don Draper
54 Mirabelle Ames Roger Sterling
55 Mona Sterling Roger Sterling
56 Paul Kinsey Peggy Olson
57 Peggy Olson Abe Drexler
58 Peggy Olson Brooklyn College Student
59 Peggy Olson Don Draper
60 Peggy Olson Duck Phillips
61 Peggy Olson Mark
62 Peggy Olson Pete Campbell
63 Pete Campbell Gudrun
64 Pete Campbell Peggy Olson
65 Pete Campbell Playtex bra model
66 Pete Campbell Trudy Campbell
67 Playtex bra model Pete Campbell
68 Rachel Menken Don Draper
69 Random guy Betty Draper
70 Rebecca Pryce Lane Pryce
71 Roger Sterling Betty Draper
72 Roger Sterling Ida Blankenship
73 Roger Sterling Jane Siegel
74 Roger Sterling Joan Holloway
75 Roger Sterling Mirabelle Ames
76 Roger Sterling Mona Sterling
77 Roger Sterling Vicky
78 Sal Romano Bellhop in Baltimore
79 Sal Romano Kitty Romano
80 Shelly Don Draper
81 Stan Rizzo Peggy Olson
82 Suzanne Farrell Don Draper
83 Toni Lane Pryce
84 Trudy Campbell Pete Campbell
85 Vicky Roger Sterling
86 Waitress Don Draper
87 Woman at the Clios party Don Draper
> g <- graph.data.frame(madmen2, directed=TRUE)
Error in graph.data.frame(madmen2, directed = TRUE) :
could not find function "graph.data.frame"
> library("ggplot2", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘ggplot2’ was built under R version 3.5.1
> library(ggplot2)
> library("igraph", lib.loc="~/R/win-library/3.5")
Attaching package: ‘igraph’
The following objects are masked from ‘package:stats’:
decompose, spectrum
The following object is masked from ‘package:base’:
union
Warning message:
package ‘igraph’ was built under R version 3.5.1
> library(igraph)
> g <- graph.data.frame(madmen2, directed=TRUE)
> par(mar=c(0,0,0,0))
> plot(g, layout=layout.fruchterman.reingold, vertex.size=8, edge.arrow.size=0.5,
+ vertex.label=NA)
>
> g <- graph.data.frame(madmen, directed=FALSE)
> par(mar=c(0,0,0,0))
> plot(g, layout=layout.circle, vertex.size=8, vertex.label=NA)
>
> plot(g, layout=layout.circle, vertex.size=10, vertex.label=NA)
> plot(g, layout=layout.circle, vertex.size=6, vertex.label=NA)
> uspopage
Year AgeGroup Thousands
1 1900 <5 9181
2 1900 5-14 16966
3 1900 15-24 14951
4 1900 25-34 12161
5 1900 35-44 9273
6 1900 45-54 6437
7 1900 55-64 4026
8 1900 >64 3099
9 1901 <5 9336
10 1901 5-14 17158
11 1901 15-24 15242
12 1901 25-34 12442
13 1901 35-44 9504
14 1901 45-54 6606
15 1901 55-64 4122
16 1901 >64 3174
17 1902 <5 9502
18 1902 5-14 17360
19 1902 15-24 15555
20 1902 25-34 12737
21 1902 35-44 9745
22 1902 45-54 6788
23 1902 55-64 4220
24 1902 >64 3256
25 1903 <5 9645
26 1903 5-14 17524
27 1903 15-24 15858
28 1903 25-34 13019
29 1903 35-44 9974
30 1903 45-54 6964
31 1903 55-64 4313
32 1903 >64 3335
33 1904 <5 9791
34 1904 5-14 17697
35 1904 15-24 16178
36 1904 25-34 13315
37 1904 35-44 10211
38 1904 45-54 7150
39 1904 55-64 4410
40 1904 >64 3414
41 1905 <5 9944
42 1905 5-14 17888
43 1905 15-24 16526
44 1905 25-34 13631
45 1905 35-44 10461
46 1905 45-54 7350
47 1905 55-64 4517
48 1905 >64 3505
49 1906 <5 10092
50 1906 5-14 18067
51 1906 15-24 16864
52 1906 25-34 13952
53 1906 35-44 10705
54 1906 45-54 7554
55 1906 55-64 4621
56 1906 >64 3595
57 1907 <5 10220
58 1907 5-14 18240
59 1907 15-24 17184
60 1907 25-34 14257
61 1907 35-44 10945
62 1907 45-54 7755
63 1907 55-64 4724
64 1907 >64 3684
65 1908 <5 10364
66 1908 5-14 18440
67 1908 15-24 17526
68 1908 25-34 14585
69 1908 35-44 11202
70 1908 45-54 7974
71 1908 55-64 4840
72 1908 >64 3779
73 1909 <5 10509
74 1909 5-14 18670
75 1909 15-24 17871
76 1909 25-34 14923
77 1909 35-44 11471
78 1909 45-54 8204
79 1909 55-64 4964
80 1909 >64 3878
81 1910 <5 10671
82 1910 5-14 18950
83 1910 15-24 18212
84 1910 25-34 15274
85 1910 35-44 11759
86 1910 45-54 8454
87 1910 55-64 5101
88 1910 >64 3986
89 1911 <5 10796
90 1911 5-14 19214
91 1911 15-24 18355
92 1911 25-34 15530
93 1911 35-44 12003
94 1911 45-54 8657
95 1911 55-64 5234
96 1911 >64 4074
97 1912 <5 10915
98 1912 5-14 19503
99 1912 15-24 18477
100 1912 25-34 15772
101 1912 35-44 12252
102 1912 45-54 8875
103 1912 55-64 5372
104 1912 >64 4169
105 1913 <5 11082
106 1913 5-14 19904
107 1913 15-24 18649
108 1913 25-34 16070
109 1913 35-44 12562
110 1913 45-54 9135
111 1913 55-64 5542
112 1913 >64 4281
113 1914 <5 11244
114 1914 5-14 20316
115 1914 15-24 18796
116 1914 25-34 16370
117 1914 35-44 12875
118 1914 45-54 9398
119 1914 55-64 5711
120 1914 >64 4401
121 1915 <5 11347
122 1915 5-14 20660
123 1915 15-24 18844
124 1915 25-34 16580
125 1915 35-44 13130
126 1915 45-54 9618
127 1915 55-64 5866
128 1915 >64 4501
129 1916 <5 11442
130 1916 5-14 21008
131 1916 15-24 18872
132 1916 25-34 16776
133 1916 35-44 13388
134 1916 45-54 9846
135 1916 55-64 6026
136 1916 >64 4603
137 1917 <5 11527
138 1917 5-14 21369
139 1917 15-24 18836
140 1917 25-34 16913
141 1917 35-44 13647
142 1917 45-54 10068
143 1917 55-64 6194
144 1917 >64 4714
145 1918 <5 11606
146 1918 5-14 21732
147 1918 15-24 18071
148 1918 25-34 16445
149 1918 35-44 13879
150 1918 45-54 10293
151 1918 55-64 6356
152 1918 >64 4826
153 1919 <5 11536
154 1919 5-14 21849
155 1919 15-24 18465
156 1919 25-34 16912
157 1919 35-44 14008
158 1919 45-54 10402
159 1919 55-64 6456
160 1919 >64 4886
161 1920 <5 11631
162 1920 5-14 22158
163 1920 15-24 18821
164 1920 25-34 17416
165 1920 35-44 14382
166 1920 45-54 10505
167 1920 55-64 6619
168 1920 >64 4929
169 1921 <5 11879
170 1921 5-14 22515
171 1921 15-24 19140
172 1921 25-34 17747
173 1921 35-44 14665
174 1921 45-54 10721
175 1921 55-64 6791
176 1921 >64 5080
177 1922 <5 12031
178 1922 5-14 22788
179 1922 15-24 19402
180 1922 25-34 17924
181 1922 35-44 14823
182 1922 45-54 10899
183 1922 55-64 6951
184 1922 >64 5231
185 1923 <5 12119
186 1923 5-14 23089
187 1923 15-24 19798
188 1923 25-34 18231
189 1923 35-44 15066
190 1923 45-54 11068
191 1923 55-64 7165
192 1923 >64 5411
193 1924 <5 12269
194 1924 5-14 23358
195 1924 15-24 20314
196 1924 25-34 18557
197 1924 35-44 15337
198 1924 45-54 11278
199 1924 55-64 7387
200 1924 >64 5609
201 1925 <5 12316
202 1925 5-14 23614
203 1925 15-24 20691
204 1925 25-34 18720
205 1925 35-44 15576
206 1925 45-54 11521
207 1925 55-64 7605
208 1925 >64 5786
209 1926 <5 12189
210 1926 5-14 23906
211 1926 15-24 21037
212 1926 25-34 18867
213 1926 35-44 15847
214 1926 45-54 11786
215 1926 55-64 7805
216 1926 >64 5960
217 1927 <5 12111
218 1927 5-14 24152
219 1927 15-24 21430
220 1927 25-34 18948
221 1927 35-44 16172
222 1927 45-54 12092
223 1927 55-64 8003
224 1927 >64 6127
225 1928 <5 11978
226 1928 5-14 24320
227 1928 15-24 21811
228 1928 25-34 18953
229 1928 35-44 16540
230 1928 45-54 12430
231 1928 55-64 8178
232 1928 >64 6299
233 1929 <5 11734
234 1929 5-14 24470
235 1929 15-24 22151
236 1929 25-34 18941
237 1929 35-44 16921
238 1929 45-54 12761
239 1929 55-64 8315
240 1929 >64 6474
241 1930 <5 11372
242 1930 5-14 24631
243 1930 15-24 22487
244 1930 25-34 19039
245 1930 35-44 17270
246 1930 45-54 13096
247 1930 55-64 8477
248 1930 >64 6705
249 1931 <5 11179
250 1931 5-14 24629
251 1931 15-24 22617
252 1931 25-34 19242
253 1931 35-44 17412
254 1931 45-54 13296
255 1931 55-64 8735
256 1931 >64 6928
257 1932 <5 10903
258 1932 5-14 24614
259 1932 15-24 22716
260 1932 25-34 19484
261 1932 35-44 17504
262 1932 45-54 13481
263 1932 55-64 8992
264 1932 >64 7147
265 1933 <5 10612
266 1933 5-14 24531
267 1933 15-24 22820
268 1933 25-34 19750
269 1933 35-44 17569
270 1933 45-54 13684
271 1933 55-64 9249
272 1933 >64 7363
273 1934 <5 10331
274 1934 5-14 24402
275 1934 15-24 22963
276 1934 25-34 20022
277 1934 35-44 17640
278 1934 45-54 13933
279 1934 55-64 9502
280 1934 >64 7582
281 1935 <5 10170
282 1935 5-14 24213
283 1935 15-24 23130
284 1935 25-34 20275
285 1935 35-44 17712
286 1935 45-54 14208
287 1935 55-64 9739
288 1935 >64 7804
289 1936 <5 10044
290 1936 5-14 23942
291 1936 15-24 23309
292 1936 25-34 20505
293 1936 35-44 17783
294 1936 45-54 14495
295 1936 55-64 9949
296 1936 >64 8027
297 1937 <5 10009
298 1937 5-14 23564
299 1937 15-24 23487
300 1937 25-34 20723
301 1937 35-44 17866
302 1937 45-54 14785
303 1937 55-64 10132
304 1937 >64 8258
305 1938 <5 10176
306 1938 5-14 23146
307 1938 15-24 23655
308 1938 25-34 20953
309 1938 35-44 18001
310 1938 45-54 15077
311 1938 55-64 10310
312 1938 >64 8508
313 1939 <5 10418
314 1939 5-14 22701
315 1939 15-24 23819
316 1939 25-34 21176
317 1939 35-44 18178
318 1939 45-54 15336
319 1939 55-64 10487
320 1939 >64 8764
321 1940 <5 10579
322 1940 5-14 22363
323 1940 15-24 24033
324 1940 25-34 21446
325 1940 35-44 18422
326 1940 45-54 15555
327 1940 55-64 10694
328 1940 >64 9031
329 1941 <5 10850
330 1941 5-14 22089
331 1941 15-24 24074
332 1941 25-34 21691
333 1941 35-44 18692
[ reached getOption("max.print") -- omitted 491 rows ]
> ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) +
+ geom_area(colour="black", size=.2, alpha=.4) +
+ scale_fill_brewer(palette="Blues", breaks=rev(levels(uspopage$AgeGroup)))
> library("plyr", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘plyr’ was built under R version 3.5.1
> library(plyr)
> ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup, order=desc(AgeGroup))) +
+ geom_area(colour="black", size=.2, alpha=.4) +
+ scale_fill_brewer(palette="Blues")
> ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup, order=desc(AgeGroup))) +
+ geom_area(colour=NA, alpha=.4) +
+ scale_fill_brewer(palette="Blues") +
+ geom_line(position="stack", size=.2)
> uspopage_prop <- ddply(uspopage, "Year", transform,
+ Percent = Thousands / sum(Thousands) * 100)
>
> ggplot(uspopage_prop, aes(x=Year, y=Percent, fill=AgeGroup)) +
+ geom_area(colour="black", size=.2, alpha=.4) +
+ scale_fill_brewer(palette="Blues", breaks=rev(levels(uspopage$AgeGroup)))
> uspopage_prop <- ddply(uspopage, "Year", transform,
+ Percent = Thousands / sum(Thousands) * 100)
>
> clim <- subset(climate, Source == "Berkeley",
+ select=c("Year", "Anomaly10y", "Unc10y"))
>
> ggplot(clim, aes(x=Year, y=Anomaly10y)) +
+ geom_ribbon(aes(ymin=Anomaly10y-Unc10y, ymax=Anomaly10y+Unc10y),
+ alpha=0.2) +
+ geom_line()
> ggplot(clim, aes(x=Year, y=Anomaly10y)) +
+ geom_line(aes(y=Anomaly10y-Unc10y), colour="grey50", linetype="dotted") +
+ geom_line(aes(y=Anomaly10y+Unc10y), colour="grey50", linetype="dotted") +
+ geom_line()
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point(shape=21)
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point(size=1.5)
> ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=sex)) + geom_point()
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex)) + geom_point()
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex, colour=sex)) +
+ geom_point()
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex, colour=sex)) +
+ geom_point() +
+ scale_shape_manual(values=c(1,2)) +
+ scale_colour_brewer(palette="Set1")
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point(shape=3)
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex)) +
+ geom_point(size=3) + scale_shape_manual(values=c(1, 4))
>
> hw <- heightweight
> hw$weightGroup <- cut(hw$weightLb, breaks=c(-Inf, 100, Inf),
+ labels=c("< 100", ">= 100"))
> ggplot(hw, aes(x=ageYear, y=heightIn, shape=sex, fill=weightGroup)) +
+ geom_point(size=2.5) +
+ scale_shape_manual(values=c(21, 24)) +
+ scale_fill_manual(values=c(NA, "black"),
+ guide=guide_legend(override.aes=list(shape=21)))
>
> heightweight[, c("sex", "ageYear", "heightIn", "weightLb")]
sex ageYear heightIn weightLb
1 f 11.92 56.3 85.0
2 f 12.92 62.3 105.0
3 f 12.75 63.3 108.0
4 f 13.42 59.0 92.0
5 f 15.92 62.5 112.5
6 f 14.25 62.5 112.0
7 f 15.42 59.0 104.0
8 f 11.83 56.5 69.0
9 f 13.33 62.0 94.5
10 f 11.67 53.8 68.5
11 f 11.58 61.5 104.0
12 f 14.83 61.5 103.5
13 f 13.08 64.5 123.5
14 f 12.42 58.3 93.0
15 f 11.92 51.3 50.5
16 f 12.08 58.8 89.0
17 f 15.92 65.3 107.0
18 f 12.50 59.5 78.5
19 f 12.25 61.3 115.0
20 f 15.00 63.3 114.0
21 f 11.75 61.8 85.0
22 f 11.67 53.5 81.0
23 f 13.67 58.0 83.5
24 f 14.67 61.3 112.0
25 f 15.42 63.3 101.0
26 f 13.83 61.5 103.5
27 f 14.58 60.8 93.5
28 f 15.00 59.0 112.0
29 f 17.50 65.5 140.0
30 f 12.17 56.3 83.5
31 f 14.17 64.3 90.0
32 f 13.50 58.0 84.0
33 f 12.42 64.3 110.5
34 f 11.58 57.5 96.0
35 f 15.50 57.8 95.0
36 f 16.42 61.5 121.0
37 f 14.08 62.3 99.5
38 f 14.75 61.8 142.5
39 f 15.42 65.3 118.0
40 f 15.17 58.3 104.5
41 f 14.42 62.8 102.5
42 f 13.83 59.3 89.5
43 f 14.00 61.5 95.0
44 f 14.08 62.0 98.5
45 f 12.50 61.3 94.0
46 f 15.33 62.3 108.0
47 f 11.58 52.8 63.5
48 f 12.25 59.8 84.5
49 f 12.00 59.5 93.5
50 f 14.75 61.3 112.0
51 f 14.83 63.5 148.5
52 f 16.42 64.8 112.0
53 f 12.17 60.0 109.0
54 f 12.08 59.0 91.5
55 f 12.25 55.8 75.0
56 f 12.08 57.8 84.0
57 f 12.92 61.3 107.0
58 f 13.92 62.3 92.5
59 f 15.25 64.3 109.5
60 f 11.92 55.5 84.0
61 f 15.25 64.5 102.5
62 f 15.42 60.0 106.0
63 f 12.33 56.3 77.0
64 f 12.25 58.3 111.5
65 f 12.83 60.0 114.0
66 f 13.00 54.5 75.0
67 f 12.00 55.8 73.5
68 f 12.83 62.8 93.5
69 f 12.67 60.5 105.0
70 f 15.92 63.3 113.5
71 f 15.83 66.8 140.0
72 f 11.67 60.0 77.0
73 f 12.33 60.5 84.5
74 f 15.75 64.3 113.5
75 f 11.92 58.3 77.5
76 f 14.83 66.5 117.5
77 f 13.67 65.3 98.0
78 f 13.08 60.5 112.0
79 f 12.25 59.5 101.0
80 f 12.33 59.0 95.0
81 f 14.75 61.3 81.0
82 f 14.25 61.5 91.0
83 f 14.33 64.8 142.0
84 f 15.83 56.8 98.5
85 f 15.25 66.5 112.0
86 f 11.92 61.5 116.5
87 f 14.92 63.0 98.5
88 f 15.50 57.0 83.5
89 f 15.17 65.5 133.0
90 f 15.17 62.0 91.5
91 f 11.83 56.0 72.5
92 f 13.75 61.3 106.5
93 f 13.75 55.5 67.0
94 f 12.83 61.0 122.5
95 f 12.50 54.5 74.0
96 f 12.92 66.0 144.5
97 f 13.58 56.5 84.0
98 f 11.75 56.0 72.5
99 f 12.25 51.5 64.0
100 f 17.50 62.0 116.0
101 f 14.25 63.0 84.0
102 f 13.92 61.0 93.5
103 f 15.17 64.0 111.5
104 f 12.00 61.0 92.0
105 f 16.08 59.8 115.0
106 f 11.75 61.3 85.0
107 f 13.67 63.3 108.0
108 f 15.50 63.5 108.0
109 f 14.08 61.5 85.0
110 f 14.58 60.3 86.0
111 f 15.00 61.3 110.5
112 m 13.75 64.8 98.0
113 m 13.08 60.5 105.0
114 m 12.00 57.3 76.5
115 m 12.50 59.5 84.0
116 m 12.50 60.8 128.0
117 m 11.58 60.5 87.0
118 m 15.75 67.0 128.0
119 m 15.25 64.8 111.0
120 m 12.25 50.5 79.0
121 m 12.17 57.5 90.0
122 m 13.33 60.5 84.0
123 m 13.00 61.8 112.0
124 m 14.42 61.3 93.0
125 m 12.58 66.3 117.0
126 m 11.75 53.3 84.0
127 m 12.50 59.0 99.5
128 m 13.67 57.8 95.0
129 m 12.75 60.0 84.0
130 m 17.17 68.3 134.0
132 m 14.67 63.8 98.5
133 m 14.67 65.0 118.5
134 m 11.67 59.5 94.5
135 m 15.42 66.0 105.0
136 m 15.00 61.8 104.0
137 m 12.17 57.3 83.0
138 m 15.25 66.0 105.5
139 m 11.67 56.5 84.0
140 m 12.58 58.3 86.0
141 m 12.58 61.0 81.0
142 m 12.00 62.8 94.0
143 m 13.33 59.3 78.5
144 m 14.83 67.3 119.5
145 m 16.08 66.3 133.0
146 m 13.50 64.5 119.0
147 m 13.67 60.5 95.0
148 m 15.50 66.0 112.0
149 m 11.92 57.5 75.0
150 m 14.58 64.0 92.0
151 m 14.58 68.0 112.0
152 m 14.58 63.5 98.5
153 m 14.42 69.0 112.5
154 m 14.17 63.8 112.5
155 m 14.50 66.0 108.0
156 m 13.67 63.5 108.0
157 m 12.00 59.5 88.0
158 m 13.00 66.3 106.0
159 m 12.42 57.0 92.0
160 m 12.00 60.0 117.5
161 m 12.25 57.0 84.0
162 m 15.67 67.3 112.0
163 m 14.08 62.0 100.0
164 m 14.33 65.0 112.0
165 m 12.50 59.5 84.0
166 m 16.08 67.8 127.5
167 m 13.08 58.0 80.5
168 m 14.00 60.0 93.5
169 m 11.67 58.5 86.5
170 m 13.00 58.3 92.5
171 m 13.00 61.5 108.5
172 m 13.17 65.0 121.0
173 m 15.33 66.5 112.0
174 m 13.00 68.5 114.0
175 m 12.00 57.0 84.0
176 m 14.67 61.5 81.0
177 m 14.00 66.5 111.5
178 m 12.42 52.5 81.0
179 m 11.83 55.0 70.0
180 m 15.67 71.0 140.0
181 m 16.92 66.5 117.0
182 m 11.83 58.8 84.0
183 m 15.75 66.3 112.0
184 m 15.67 65.8 150.5
185 m 16.67 71.0 147.0
186 m 12.67 59.5 105.0
187 m 14.50 69.8 119.5
188 m 13.83 62.5 84.0
189 m 12.08 56.5 91.0
190 m 11.92 57.5 101.0
191 m 13.58 65.3 117.5
192 m 13.83 67.3 121.0
193 m 15.17 67.0 133.0
194 m 14.42 66.0 112.0
195 m 12.92 61.8 91.5
196 m 13.50 60.0 105.0
197 m 14.75 63.0 111.0
198 m 14.75 60.5 112.0
199 m 14.58 65.5 114.0
200 m 13.83 62.0 91.0
201 m 12.50 59.0 98.0
202 m 12.50 61.8 118.0
203 m 15.67 63.3 115.5
204 m 13.58 66.0 112.0
205 m 14.25 61.8 112.0
206 m 13.50 63.0 91.0
207 m 11.75 57.5 85.0
208 m 14.50 63.0 112.0
209 m 11.83 56.0 87.5
210 m 12.33 60.5 118.0
211 m 11.67 56.8 83.5
212 m 13.33 64.0 116.0
213 m 12.00 60.0 89.0
214 m 17.17 69.5 171.5
215 m 13.25 63.3 112.0
216 m 12.42 56.3 72.0
217 m 16.08 72.0 150.0
218 m 16.17 65.3 134.5
219 m 12.67 60.8 97.0
220 m 12.17 55.0 71.5
221 m 11.58 55.0 73.5
222 m 15.50 66.5 112.0
223 m 13.42 56.8 75.0
224 m 12.75 64.8 128.0
225 m 16.33 64.5 98.0
226 m 13.67 58.0 84.0
227 m 13.25 62.8 99.0
228 m 14.83 63.8 112.0
229 m 12.75 57.8 79.5
230 m 12.92 57.3 80.5
231 m 14.83 63.5 102.5
232 m 11.83 55.0 76.0
233 m 13.67 66.5 112.0
234 m 15.75 65.0 114.0
235 m 13.67 61.5 140.0
236 m 13.92 62.0 107.5
237 m 12.58 59.3 87.0
> ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=weightLb)) + geom_point()
> ggplot(heightweight, aes(x=ageYear, y=heightIn, size=weightLb)) + geom_point()
>
> ggplot(heightweight, aes(x=weightLb, y=heightIn, fill=ageYear)) +
+ geom_point(shape=21, size=2.5) +
+ scale_fill_gradient(low="black", high="white")
> ggplot(heightweight, aes(x=weightLb, y=heightIn, fill=ageYear)) +
+ geom_point(shape=21, size=2.5) +
+ scale_fill_gradient(low="black", high="white", breaks=12:17,
+ guide=guide_legend())
> ggplot(heightweight, aes(x=ageYear, y=heightIn, size=weightLb, colour=sex)) +
+ geom_point(alpha=.5) +
+ scale_size_area() + # Make area proportional to numeric value
+ scale_colour_brewer(palette="Set1")
>
> p <- ggplot(heightweight, aes(x=sex, y=heightIn))
> p + geom_violin()
> p + geom_violin() + geom_boxplot(width=.1, fill="black", outlier.colour=NA) +
+ stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=2.5)
> p + geom_violin(trim=FALSE)
>
> p + geom_violin(scale="count")
>
> p + geom_violin(adjust=2)
> p + geom_violin(adjust=.5)
> countries2009 <- subset(countries, Year==2009 & healthexp>2000)
> p <- ggplot(countries2009, aes(x=infmortality))
>
> p + geom_dotplot()
`stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
>
> p + geom_dotplot(binwidth=.25) + geom_rug() +
+ scale_y_continuous(breaks=NULL) + # Remove tick markers
+ theme(axis.title.y=element_blank())
> p + geom_dotplot(method="histodot", binwidth=.25) + geom_rug() +
+ scale_y_continuous(breaks=NULL) + theme(axis.title.y=element_blank())
> p + geom_dotplot(binwidth=.25, stackdir="center")
> scale_y_continuous(breaks=NULL) + theme(axis.title.y=element_blank())
Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
> p + geom_dotplot(binwidth=.25, stackdir="centerwhole")
> scale_y_continuous(breaks=NULL) + theme(axis.title.y=element_blank())
Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
>
> ggplot(heightweight, aes(x=sex, y=heightIn)) +
+ geom_dotplot(binaxis="y", binwidth=.5, stackdir="center")
> ggplot(heightweight, aes(x=sex, y=heightIn)) +
+ geom_boxplot(outlier.colour=NA, width=.4) +
+ geom_dotplot(binaxis="y", binwidth=.5, stackdir="center", fill=NA)
> ggplot(heightweight, aes(x=sex, y=heightIn)) +
+ geom_boxplot(aes(x=as.numeric(sex) + .2, group=sex), width=.25) +
+ geom_dotplot(aes(x=as.numeric(sex) - .2, group=sex), binaxis="y",
+ binwidth=.5, stackdir="center") +
+ scale_x_continuous(breaks=1:nlevels(heightweight$sex),
+ labels=levels(heightweight$sex))
>
> library("plot3D", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘plot3D’ was built under R version 3.5.2
> library(plot3D)
> p <- ggplot(faithful, aes(x=eruptions, y=waiting))
>
> p + geom_point() + stat_density3d()
Error in stat_density3d() : could not find function "stat_density3d"
> p + geom_point() + stat_density2d()
> p + stat_density2d(aes(colour=..level..))
> p + stat_density2d(aes(fill=..density..), geom="raster", contour=FALSE)
>
> p + geom_point() +
+ stat_density2d(aes(alpha=..density..), geom="tile", contour=FALSE)
>
> p + stat_density2d(aes(fill=..density..), geom="raster",
+ contour=FALSE, h=c(.5,5))
>
> p <- ggplot(faithful, aes(x=eruptions, y=waiting)) + geom_point()
>
> p + annotate("text", x=3, y=48, label="Group 1") +
+ annotate("text", x=4.5, y=66, label="Group 2")
> p + annotate("text", x=3, y=48, label="Group 1", family="serif",
+ fontface="italic", colour="darkred", size=3) +
+ annotate("text", x=4.5, y=66, label="Group 2", family="serif",
+ fontface="italic", colour="darkred", size=3)
>
> geom_text(x=4.5, y=66, label="Group 2", alpha=.1)
geom_text: parse = FALSE, check_overlap = FALSE, na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity
> p + annotate("text", x=-Inf, y=Inf, label="Upper left", hjust=-.2, vjust=2) +
+ annotate("text", x=mean(range(faithful$eruptions)), y=-Inf, vjust=-0.4,
+ label="Bottom middle")
>
> p <- ggplot(data.frame(x=c(-3,3)), aes(x=x)) + stat_function(fun = dnorm)
>
> p + annotate("text", x=2, y=0.3, parse=TRUE,
+ label="frac(1, sqrt(2 * pi)) * e ^ {-x^2 / 2}")
> p + annotate("text", x=0, y=0.05, parse=TRUE, size=4,
+ label="'Function: ' * y==frac(1, sqrt(2*pi)) * e^{-x^2/2}")
> p <- ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=sex)) + geom_point()
>
> p + geom_hline(yintercept=60) + geom_vline(xintercept=14)
>
> p + geom_abline(intercept=37.4, slope=1.75)
> ggplot(wind, aes(x=DirCat, fill=SpeedCat)) +
+ geom_histogram(binwidth=15, origin=-7.5) +
+ coord_polar() +
+ scale_x_continuous(limits=c(0,360))
Warning messages:
1: `origin` is deprecated. Please use `boundary` instead.
2: Removed 8 rows containing missing values (geom_bar).
> ggplot(wind, aes(x=DirCat, fill=SpeedCat)) +
+ geom_histogram(binwidth=15, origin=-7.5, colour="black", size=.25) +
+ guides(fill=guide_legend(reverse=TRUE)) +
+ coord_polar() +
+ scale_x_continuous(limits=c(0,360), breaks=seq(0, 360, by=45),
+ minor_breaks=seq(0, 360, by=15)) +
+ scale_fill_brewer()
Warning messages:
1: `origin` is deprecated. Please use `boundary` instead.
2: Removed 8 rows containing missing values (geom_bar).
>
> p <- ggplot(md, aes(x=month, y=deaths)) + geom_line() +
+ scale_x_continuous(breaks=1:12)
Error in ggplot(md, aes(x = month, y = deaths)) : object 'md' not found
> md <- ddply(md, "month", summarise, deaths = mean(deaths))
Error in empty(.data) : object 'md' not found
>
> p <- ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
>
> p + theme(axis.title.x=element_text(size=16, lineheight=.9, family="Times",
+ face="bold.italic", colour="red"))
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
> p + ggtitle("Age and Height\nof Schoolchildren") +
+ theme(plot.title=element_text(size=rel(1.5), lineheight=.9, family="Times",
+ face="bold.italic", colour="red"))
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
6: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
7: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
8: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
9: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p + annotate("text", x=15, y=53, label="Some text", size = 7, family="Times",
+ fontface="bold.italic", colour="red")
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
6: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
7: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p + geom_text(aes(label=weightLb), size=4, family="Times", colour="red")
Warning messages:
1: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p + theme_grey(base_size=16, base_family="Times")
Warning messages:
1: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
6: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
7: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
8: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
9: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
10: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p <- ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=sex)) + geom_point()
There were 16 warnings (use warnings() to see them)
> p + theme(
+ panel.grid.major = element_line(colour="red"),
+ panel.grid.minor = element_line(colour="red", linetype="dashed", size=0.2),
+ panel.background = element_rect(fill="lightblue"),
+ panel.border = element_rect(colour="blue", fill=NA, size=2))
> p <- ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) + geom_area()
>
> p + scale_fill_discrete()
> p + scale_fill_hue()
>
> p + scale_fill_brewer()
install.packages("gcookbook")
Installing package into ‘C:/Users/ADMIN/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/gcookbook_2.0.zip'
Content type 'application/zip' length 4012215 bytes (3.8 MB)
downloaded 3.8 MB
package ‘gcookbook’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\ADMIN\AppData\Local\Temp\RtmpWmK7Tq\downloaded_packages
> library(gcookbook)
Warning message:
package ‘gcookbook’ was built under R version 3.5.2
> library(gcookbook)
> madmen2
Name1 Name2
1 Abe Drexler Peggy Olson
2 Allison Don Draper
3 Arthur Case Betty Draper
4 Bellhop in Baltimore Sal Romano
5 Bethany Van Nuys Don Draper
6 Betty Draper Don Draper
7 Betty Draper Henry Francis
8 Betty Draper Random guy
9 Bobbie Barrett Don Draper
10 Brooklyn College Student Peggy Olson
11 Candace Don Draper
12 Don Draper Allison
13 Don Draper Bethany Van Nuys
14 Don Draper Betty Draper
15 Don Draper Bobbie Barrett
16 Don Draper Candace
17 Don Draper Doris
18 Don Draper Faye Miller
19 Don Draper Joy
20 Don Draper Megan Calvet
21 Don Draper Midge Daniels
22 Don Draper Rachel Menken
23 Don Draper Shelly
24 Don Draper Suzanne Farrell
25 Don Draper Woman at the Clios party
26 Doris Don Draper
27 Duck Phillips Peggy Olson
28 Elliot Sal Romano
29 Faye Miller Don Draper
30 Franklin Joan Holloway
31 Greg Harris Joan Holloway
32 Gudrun Pete Campbell
33 Harry Crane Hildy
34 Harry Crane Jennifer Crane
35 Henry Francis Betty Draper
36 Hildy Harry Crane
37 Ida Blankenship Roger Sterling
38 Jane Siegel Roger Sterling
39 Janine Lane Pryce
40 Jennifer Crane Harry Crane
41 Joan Holloway Franklin
42 Joan Holloway Greg Harris
43 Joan Holloway Roger Sterling
44 Joy Don Draper
45 Joyce Ramsay Peggy Olson
46 Kitty Romano Sal Romano
47 Lane Pryce Janine
48 Lane Pryce Rebecca Pryce
49 Lane Pryce Toni
50 Lee Garner Jr. Sal Romano
51 Mark Peggy Olson
52 Megan Calvet Don Draper
53 Midge Daniels Don Draper
54 Mirabelle Ames Roger Sterling
55 Mona Sterling Roger Sterling
56 Paul Kinsey Peggy Olson
57 Peggy Olson Abe Drexler
58 Peggy Olson Brooklyn College Student
59 Peggy Olson Don Draper
60 Peggy Olson Duck Phillips
61 Peggy Olson Mark
62 Peggy Olson Pete Campbell
63 Pete Campbell Gudrun
64 Pete Campbell Peggy Olson
65 Pete Campbell Playtex bra model
66 Pete Campbell Trudy Campbell
67 Playtex bra model Pete Campbell
68 Rachel Menken Don Draper
69 Random guy Betty Draper
70 Rebecca Pryce Lane Pryce
71 Roger Sterling Betty Draper
72 Roger Sterling Ida Blankenship
73 Roger Sterling Jane Siegel
74 Roger Sterling Joan Holloway
75 Roger Sterling Mirabelle Ames
76 Roger Sterling Mona Sterling
77 Roger Sterling Vicky
78 Sal Romano Bellhop in Baltimore
79 Sal Romano Kitty Romano
80 Shelly Don Draper
81 Stan Rizzo Peggy Olson
82 Suzanne Farrell Don Draper
83 Toni Lane Pryce
84 Trudy Campbell Pete Campbell
85 Vicky Roger Sterling
86 Waitress Don Draper
87 Woman at the Clios party Don Draper
> g <- graph.data.frame(madmen2, directed=TRUE)
Error in graph.data.frame(madmen2, directed = TRUE) :
could not find function "graph.data.frame"
> library("ggplot2", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘ggplot2’ was built under R version 3.5.1
> library(ggplot2)
> library("igraph", lib.loc="~/R/win-library/3.5")
Attaching package: ‘igraph’
The following objects are masked from ‘package:stats’:
decompose, spectrum
The following object is masked from ‘package:base’:
union
Warning message:
package ‘igraph’ was built under R version 3.5.1
> library(igraph)
> g <- graph.data.frame(madmen2, directed=TRUE)
> par(mar=c(0,0,0,0))
> plot(g, layout=layout.fruchterman.reingold, vertex.size=8, edge.arrow.size=0.5,
+ vertex.label=NA)
>
> g <- graph.data.frame(madmen, directed=FALSE)
> par(mar=c(0,0,0,0))
> plot(g, layout=layout.circle, vertex.size=8, vertex.label=NA)
>
> plot(g, layout=layout.circle, vertex.size=10, vertex.label=NA)
> plot(g, layout=layout.circle, vertex.size=6, vertex.label=NA)
> uspopage
Year AgeGroup Thousands
1 1900 <5 9181
2 1900 5-14 16966
3 1900 15-24 14951
4 1900 25-34 12161
5 1900 35-44 9273
6 1900 45-54 6437
7 1900 55-64 4026
8 1900 >64 3099
9 1901 <5 9336
10 1901 5-14 17158
11 1901 15-24 15242
12 1901 25-34 12442
13 1901 35-44 9504
14 1901 45-54 6606
15 1901 55-64 4122
16 1901 >64 3174
17 1902 <5 9502
18 1902 5-14 17360
19 1902 15-24 15555
20 1902 25-34 12737
21 1902 35-44 9745
22 1902 45-54 6788
23 1902 55-64 4220
24 1902 >64 3256
25 1903 <5 9645
26 1903 5-14 17524
27 1903 15-24 15858
28 1903 25-34 13019
29 1903 35-44 9974
30 1903 45-54 6964
31 1903 55-64 4313
32 1903 >64 3335
33 1904 <5 9791
34 1904 5-14 17697
35 1904 15-24 16178
36 1904 25-34 13315
37 1904 35-44 10211
38 1904 45-54 7150
39 1904 55-64 4410
40 1904 >64 3414
41 1905 <5 9944
42 1905 5-14 17888
43 1905 15-24 16526
44 1905 25-34 13631
45 1905 35-44 10461
46 1905 45-54 7350
47 1905 55-64 4517
48 1905 >64 3505
49 1906 <5 10092
50 1906 5-14 18067
51 1906 15-24 16864
52 1906 25-34 13952
53 1906 35-44 10705
54 1906 45-54 7554
55 1906 55-64 4621
56 1906 >64 3595
57 1907 <5 10220
58 1907 5-14 18240
59 1907 15-24 17184
60 1907 25-34 14257
61 1907 35-44 10945
62 1907 45-54 7755
63 1907 55-64 4724
64 1907 >64 3684
65 1908 <5 10364
66 1908 5-14 18440
67 1908 15-24 17526
68 1908 25-34 14585
69 1908 35-44 11202
70 1908 45-54 7974
71 1908 55-64 4840
72 1908 >64 3779
73 1909 <5 10509
74 1909 5-14 18670
75 1909 15-24 17871
76 1909 25-34 14923
77 1909 35-44 11471
78 1909 45-54 8204
79 1909 55-64 4964
80 1909 >64 3878
81 1910 <5 10671
82 1910 5-14 18950
83 1910 15-24 18212
84 1910 25-34 15274
85 1910 35-44 11759
86 1910 45-54 8454
87 1910 55-64 5101
88 1910 >64 3986
89 1911 <5 10796
90 1911 5-14 19214
91 1911 15-24 18355
92 1911 25-34 15530
93 1911 35-44 12003
94 1911 45-54 8657
95 1911 55-64 5234
96 1911 >64 4074
97 1912 <5 10915
98 1912 5-14 19503
99 1912 15-24 18477
100 1912 25-34 15772
101 1912 35-44 12252
102 1912 45-54 8875
103 1912 55-64 5372
104 1912 >64 4169
105 1913 <5 11082
106 1913 5-14 19904
107 1913 15-24 18649
108 1913 25-34 16070
109 1913 35-44 12562
110 1913 45-54 9135
111 1913 55-64 5542
112 1913 >64 4281
113 1914 <5 11244
114 1914 5-14 20316
115 1914 15-24 18796
116 1914 25-34 16370
117 1914 35-44 12875
118 1914 45-54 9398
119 1914 55-64 5711
120 1914 >64 4401
121 1915 <5 11347
122 1915 5-14 20660
123 1915 15-24 18844
124 1915 25-34 16580
125 1915 35-44 13130
126 1915 45-54 9618
127 1915 55-64 5866
128 1915 >64 4501
129 1916 <5 11442
130 1916 5-14 21008
131 1916 15-24 18872
132 1916 25-34 16776
133 1916 35-44 13388
134 1916 45-54 9846
135 1916 55-64 6026
136 1916 >64 4603
137 1917 <5 11527
138 1917 5-14 21369
139 1917 15-24 18836
140 1917 25-34 16913
141 1917 35-44 13647
142 1917 45-54 10068
143 1917 55-64 6194
144 1917 >64 4714
145 1918 <5 11606
146 1918 5-14 21732
147 1918 15-24 18071
148 1918 25-34 16445
149 1918 35-44 13879
150 1918 45-54 10293
151 1918 55-64 6356
152 1918 >64 4826
153 1919 <5 11536
154 1919 5-14 21849
155 1919 15-24 18465
156 1919 25-34 16912
157 1919 35-44 14008
158 1919 45-54 10402
159 1919 55-64 6456
160 1919 >64 4886
161 1920 <5 11631
162 1920 5-14 22158
163 1920 15-24 18821
164 1920 25-34 17416
165 1920 35-44 14382
166 1920 45-54 10505
167 1920 55-64 6619
168 1920 >64 4929
169 1921 <5 11879
170 1921 5-14 22515
171 1921 15-24 19140
172 1921 25-34 17747
173 1921 35-44 14665
174 1921 45-54 10721
175 1921 55-64 6791
176 1921 >64 5080
177 1922 <5 12031
178 1922 5-14 22788
179 1922 15-24 19402
180 1922 25-34 17924
181 1922 35-44 14823
182 1922 45-54 10899
183 1922 55-64 6951
184 1922 >64 5231
185 1923 <5 12119
186 1923 5-14 23089
187 1923 15-24 19798
188 1923 25-34 18231
189 1923 35-44 15066
190 1923 45-54 11068
191 1923 55-64 7165
192 1923 >64 5411
193 1924 <5 12269
194 1924 5-14 23358
195 1924 15-24 20314
196 1924 25-34 18557
197 1924 35-44 15337
198 1924 45-54 11278
199 1924 55-64 7387
200 1924 >64 5609
201 1925 <5 12316
202 1925 5-14 23614
203 1925 15-24 20691
204 1925 25-34 18720
205 1925 35-44 15576
206 1925 45-54 11521
207 1925 55-64 7605
208 1925 >64 5786
209 1926 <5 12189
210 1926 5-14 23906
211 1926 15-24 21037
212 1926 25-34 18867
213 1926 35-44 15847
214 1926 45-54 11786
215 1926 55-64 7805
216 1926 >64 5960
217 1927 <5 12111
218 1927 5-14 24152
219 1927 15-24 21430
220 1927 25-34 18948
221 1927 35-44 16172
222 1927 45-54 12092
223 1927 55-64 8003
224 1927 >64 6127
225 1928 <5 11978
226 1928 5-14 24320
227 1928 15-24 21811
228 1928 25-34 18953
229 1928 35-44 16540
230 1928 45-54 12430
231 1928 55-64 8178
232 1928 >64 6299
233 1929 <5 11734
234 1929 5-14 24470
235 1929 15-24 22151
236 1929 25-34 18941
237 1929 35-44 16921
238 1929 45-54 12761
239 1929 55-64 8315
240 1929 >64 6474
241 1930 <5 11372
242 1930 5-14 24631
243 1930 15-24 22487
244 1930 25-34 19039
245 1930 35-44 17270
246 1930 45-54 13096
247 1930 55-64 8477
248 1930 >64 6705
249 1931 <5 11179
250 1931 5-14 24629
251 1931 15-24 22617
252 1931 25-34 19242
253 1931 35-44 17412
254 1931 45-54 13296
255 1931 55-64 8735
256 1931 >64 6928
257 1932 <5 10903
258 1932 5-14 24614
259 1932 15-24 22716
260 1932 25-34 19484
261 1932 35-44 17504
262 1932 45-54 13481
263 1932 55-64 8992
264 1932 >64 7147
265 1933 <5 10612
266 1933 5-14 24531
267 1933 15-24 22820
268 1933 25-34 19750
269 1933 35-44 17569
270 1933 45-54 13684
271 1933 55-64 9249
272 1933 >64 7363
273 1934 <5 10331
274 1934 5-14 24402
275 1934 15-24 22963
276 1934 25-34 20022
277 1934 35-44 17640
278 1934 45-54 13933
279 1934 55-64 9502
280 1934 >64 7582
281 1935 <5 10170
282 1935 5-14 24213
283 1935 15-24 23130
284 1935 25-34 20275
285 1935 35-44 17712
286 1935 45-54 14208
287 1935 55-64 9739
288 1935 >64 7804
289 1936 <5 10044
290 1936 5-14 23942
291 1936 15-24 23309
292 1936 25-34 20505
293 1936 35-44 17783
294 1936 45-54 14495
295 1936 55-64 9949
296 1936 >64 8027
297 1937 <5 10009
298 1937 5-14 23564
299 1937 15-24 23487
300 1937 25-34 20723
301 1937 35-44 17866
302 1937 45-54 14785
303 1937 55-64 10132
304 1937 >64 8258
305 1938 <5 10176
306 1938 5-14 23146
307 1938 15-24 23655
308 1938 25-34 20953
309 1938 35-44 18001
310 1938 45-54 15077
311 1938 55-64 10310
312 1938 >64 8508
313 1939 <5 10418
314 1939 5-14 22701
315 1939 15-24 23819
316 1939 25-34 21176
317 1939 35-44 18178
318 1939 45-54 15336
319 1939 55-64 10487
320 1939 >64 8764
321 1940 <5 10579
322 1940 5-14 22363
323 1940 15-24 24033
324 1940 25-34 21446
325 1940 35-44 18422
326 1940 45-54 15555
327 1940 55-64 10694
328 1940 >64 9031
329 1941 <5 10850
330 1941 5-14 22089
331 1941 15-24 24074
332 1941 25-34 21691
333 1941 35-44 18692
[ reached getOption("max.print") -- omitted 491 rows ]
> ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) +
+ geom_area(colour="black", size=.2, alpha=.4) +
+ scale_fill_brewer(palette="Blues", breaks=rev(levels(uspopage$AgeGroup)))
> library("plyr", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘plyr’ was built under R version 3.5.1
> library(plyr)
> ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup, order=desc(AgeGroup))) +
+ geom_area(colour="black", size=.2, alpha=.4) +
+ scale_fill_brewer(palette="Blues")
> ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup, order=desc(AgeGroup))) +
+ geom_area(colour=NA, alpha=.4) +
+ scale_fill_brewer(palette="Blues") +
+ geom_line(position="stack", size=.2)
> uspopage_prop <- ddply(uspopage, "Year", transform,
+ Percent = Thousands / sum(Thousands) * 100)
>
> ggplot(uspopage_prop, aes(x=Year, y=Percent, fill=AgeGroup)) +
+ geom_area(colour="black", size=.2, alpha=.4) +
+ scale_fill_brewer(palette="Blues", breaks=rev(levels(uspopage$AgeGroup)))
> uspopage_prop <- ddply(uspopage, "Year", transform,
+ Percent = Thousands / sum(Thousands) * 100)
>
> clim <- subset(climate, Source == "Berkeley",
+ select=c("Year", "Anomaly10y", "Unc10y"))
>
> ggplot(clim, aes(x=Year, y=Anomaly10y)) +
+ geom_ribbon(aes(ymin=Anomaly10y-Unc10y, ymax=Anomaly10y+Unc10y),
+ alpha=0.2) +
+ geom_line()
> ggplot(clim, aes(x=Year, y=Anomaly10y)) +
+ geom_line(aes(y=Anomaly10y-Unc10y), colour="grey50", linetype="dotted") +
+ geom_line(aes(y=Anomaly10y+Unc10y), colour="grey50", linetype="dotted") +
+ geom_line()
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point(shape=21)
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point(size=1.5)
> ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=sex)) + geom_point()
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex)) + geom_point()
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex, colour=sex)) +
+ geom_point()
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex, colour=sex)) +
+ geom_point() +
+ scale_shape_manual(values=c(1,2)) +
+ scale_colour_brewer(palette="Set1")
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point(shape=3)
>
> ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex)) +
+ geom_point(size=3) + scale_shape_manual(values=c(1, 4))
>
> hw <- heightweight
> hw$weightGroup <- cut(hw$weightLb, breaks=c(-Inf, 100, Inf),
+ labels=c("< 100", ">= 100"))
> ggplot(hw, aes(x=ageYear, y=heightIn, shape=sex, fill=weightGroup)) +
+ geom_point(size=2.5) +
+ scale_shape_manual(values=c(21, 24)) +
+ scale_fill_manual(values=c(NA, "black"),
+ guide=guide_legend(override.aes=list(shape=21)))
>
> heightweight[, c("sex", "ageYear", "heightIn", "weightLb")]
sex ageYear heightIn weightLb
1 f 11.92 56.3 85.0
2 f 12.92 62.3 105.0
3 f 12.75 63.3 108.0
4 f 13.42 59.0 92.0
5 f 15.92 62.5 112.5
6 f 14.25 62.5 112.0
7 f 15.42 59.0 104.0
8 f 11.83 56.5 69.0
9 f 13.33 62.0 94.5
10 f 11.67 53.8 68.5
11 f 11.58 61.5 104.0
12 f 14.83 61.5 103.5
13 f 13.08 64.5 123.5
14 f 12.42 58.3 93.0
15 f 11.92 51.3 50.5
16 f 12.08 58.8 89.0
17 f 15.92 65.3 107.0
18 f 12.50 59.5 78.5
19 f 12.25 61.3 115.0
20 f 15.00 63.3 114.0
21 f 11.75 61.8 85.0
22 f 11.67 53.5 81.0
23 f 13.67 58.0 83.5
24 f 14.67 61.3 112.0
25 f 15.42 63.3 101.0
26 f 13.83 61.5 103.5
27 f 14.58 60.8 93.5
28 f 15.00 59.0 112.0
29 f 17.50 65.5 140.0
30 f 12.17 56.3 83.5
31 f 14.17 64.3 90.0
32 f 13.50 58.0 84.0
33 f 12.42 64.3 110.5
34 f 11.58 57.5 96.0
35 f 15.50 57.8 95.0
36 f 16.42 61.5 121.0
37 f 14.08 62.3 99.5
38 f 14.75 61.8 142.5
39 f 15.42 65.3 118.0
40 f 15.17 58.3 104.5
41 f 14.42 62.8 102.5
42 f 13.83 59.3 89.5
43 f 14.00 61.5 95.0
44 f 14.08 62.0 98.5
45 f 12.50 61.3 94.0
46 f 15.33 62.3 108.0
47 f 11.58 52.8 63.5
48 f 12.25 59.8 84.5
49 f 12.00 59.5 93.5
50 f 14.75 61.3 112.0
51 f 14.83 63.5 148.5
52 f 16.42 64.8 112.0
53 f 12.17 60.0 109.0
54 f 12.08 59.0 91.5
55 f 12.25 55.8 75.0
56 f 12.08 57.8 84.0
57 f 12.92 61.3 107.0
58 f 13.92 62.3 92.5
59 f 15.25 64.3 109.5
60 f 11.92 55.5 84.0
61 f 15.25 64.5 102.5
62 f 15.42 60.0 106.0
63 f 12.33 56.3 77.0
64 f 12.25 58.3 111.5
65 f 12.83 60.0 114.0
66 f 13.00 54.5 75.0
67 f 12.00 55.8 73.5
68 f 12.83 62.8 93.5
69 f 12.67 60.5 105.0
70 f 15.92 63.3 113.5
71 f 15.83 66.8 140.0
72 f 11.67 60.0 77.0
73 f 12.33 60.5 84.5
74 f 15.75 64.3 113.5
75 f 11.92 58.3 77.5
76 f 14.83 66.5 117.5
77 f 13.67 65.3 98.0
78 f 13.08 60.5 112.0
79 f 12.25 59.5 101.0
80 f 12.33 59.0 95.0
81 f 14.75 61.3 81.0
82 f 14.25 61.5 91.0
83 f 14.33 64.8 142.0
84 f 15.83 56.8 98.5
85 f 15.25 66.5 112.0
86 f 11.92 61.5 116.5
87 f 14.92 63.0 98.5
88 f 15.50 57.0 83.5
89 f 15.17 65.5 133.0
90 f 15.17 62.0 91.5
91 f 11.83 56.0 72.5
92 f 13.75 61.3 106.5
93 f 13.75 55.5 67.0
94 f 12.83 61.0 122.5
95 f 12.50 54.5 74.0
96 f 12.92 66.0 144.5
97 f 13.58 56.5 84.0
98 f 11.75 56.0 72.5
99 f 12.25 51.5 64.0
100 f 17.50 62.0 116.0
101 f 14.25 63.0 84.0
102 f 13.92 61.0 93.5
103 f 15.17 64.0 111.5
104 f 12.00 61.0 92.0
105 f 16.08 59.8 115.0
106 f 11.75 61.3 85.0
107 f 13.67 63.3 108.0
108 f 15.50 63.5 108.0
109 f 14.08 61.5 85.0
110 f 14.58 60.3 86.0
111 f 15.00 61.3 110.5
112 m 13.75 64.8 98.0
113 m 13.08 60.5 105.0
114 m 12.00 57.3 76.5
115 m 12.50 59.5 84.0
116 m 12.50 60.8 128.0
117 m 11.58 60.5 87.0
118 m 15.75 67.0 128.0
119 m 15.25 64.8 111.0
120 m 12.25 50.5 79.0
121 m 12.17 57.5 90.0
122 m 13.33 60.5 84.0
123 m 13.00 61.8 112.0
124 m 14.42 61.3 93.0
125 m 12.58 66.3 117.0
126 m 11.75 53.3 84.0
127 m 12.50 59.0 99.5
128 m 13.67 57.8 95.0
129 m 12.75 60.0 84.0
130 m 17.17 68.3 134.0
132 m 14.67 63.8 98.5
133 m 14.67 65.0 118.5
134 m 11.67 59.5 94.5
135 m 15.42 66.0 105.0
136 m 15.00 61.8 104.0
137 m 12.17 57.3 83.0
138 m 15.25 66.0 105.5
139 m 11.67 56.5 84.0
140 m 12.58 58.3 86.0
141 m 12.58 61.0 81.0
142 m 12.00 62.8 94.0
143 m 13.33 59.3 78.5
144 m 14.83 67.3 119.5
145 m 16.08 66.3 133.0
146 m 13.50 64.5 119.0
147 m 13.67 60.5 95.0
148 m 15.50 66.0 112.0
149 m 11.92 57.5 75.0
150 m 14.58 64.0 92.0
151 m 14.58 68.0 112.0
152 m 14.58 63.5 98.5
153 m 14.42 69.0 112.5
154 m 14.17 63.8 112.5
155 m 14.50 66.0 108.0
156 m 13.67 63.5 108.0
157 m 12.00 59.5 88.0
158 m 13.00 66.3 106.0
159 m 12.42 57.0 92.0
160 m 12.00 60.0 117.5
161 m 12.25 57.0 84.0
162 m 15.67 67.3 112.0
163 m 14.08 62.0 100.0
164 m 14.33 65.0 112.0
165 m 12.50 59.5 84.0
166 m 16.08 67.8 127.5
167 m 13.08 58.0 80.5
168 m 14.00 60.0 93.5
169 m 11.67 58.5 86.5
170 m 13.00 58.3 92.5
171 m 13.00 61.5 108.5
172 m 13.17 65.0 121.0
173 m 15.33 66.5 112.0
174 m 13.00 68.5 114.0
175 m 12.00 57.0 84.0
176 m 14.67 61.5 81.0
177 m 14.00 66.5 111.5
178 m 12.42 52.5 81.0
179 m 11.83 55.0 70.0
180 m 15.67 71.0 140.0
181 m 16.92 66.5 117.0
182 m 11.83 58.8 84.0
183 m 15.75 66.3 112.0
184 m 15.67 65.8 150.5
185 m 16.67 71.0 147.0
186 m 12.67 59.5 105.0
187 m 14.50 69.8 119.5
188 m 13.83 62.5 84.0
189 m 12.08 56.5 91.0
190 m 11.92 57.5 101.0
191 m 13.58 65.3 117.5
192 m 13.83 67.3 121.0
193 m 15.17 67.0 133.0
194 m 14.42 66.0 112.0
195 m 12.92 61.8 91.5
196 m 13.50 60.0 105.0
197 m 14.75 63.0 111.0
198 m 14.75 60.5 112.0
199 m 14.58 65.5 114.0
200 m 13.83 62.0 91.0
201 m 12.50 59.0 98.0
202 m 12.50 61.8 118.0
203 m 15.67 63.3 115.5
204 m 13.58 66.0 112.0
205 m 14.25 61.8 112.0
206 m 13.50 63.0 91.0
207 m 11.75 57.5 85.0
208 m 14.50 63.0 112.0
209 m 11.83 56.0 87.5
210 m 12.33 60.5 118.0
211 m 11.67 56.8 83.5
212 m 13.33 64.0 116.0
213 m 12.00 60.0 89.0
214 m 17.17 69.5 171.5
215 m 13.25 63.3 112.0
216 m 12.42 56.3 72.0
217 m 16.08 72.0 150.0
218 m 16.17 65.3 134.5
219 m 12.67 60.8 97.0
220 m 12.17 55.0 71.5
221 m 11.58 55.0 73.5
222 m 15.50 66.5 112.0
223 m 13.42 56.8 75.0
224 m 12.75 64.8 128.0
225 m 16.33 64.5 98.0
226 m 13.67 58.0 84.0
227 m 13.25 62.8 99.0
228 m 14.83 63.8 112.0
229 m 12.75 57.8 79.5
230 m 12.92 57.3 80.5
231 m 14.83 63.5 102.5
232 m 11.83 55.0 76.0
233 m 13.67 66.5 112.0
234 m 15.75 65.0 114.0
235 m 13.67 61.5 140.0
236 m 13.92 62.0 107.5
237 m 12.58 59.3 87.0
> ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=weightLb)) + geom_point()
> ggplot(heightweight, aes(x=ageYear, y=heightIn, size=weightLb)) + geom_point()
>
> ggplot(heightweight, aes(x=weightLb, y=heightIn, fill=ageYear)) +
+ geom_point(shape=21, size=2.5) +
+ scale_fill_gradient(low="black", high="white")
> ggplot(heightweight, aes(x=weightLb, y=heightIn, fill=ageYear)) +
+ geom_point(shape=21, size=2.5) +
+ scale_fill_gradient(low="black", high="white", breaks=12:17,
+ guide=guide_legend())
> ggplot(heightweight, aes(x=ageYear, y=heightIn, size=weightLb, colour=sex)) +
+ geom_point(alpha=.5) +
+ scale_size_area() + # Make area proportional to numeric value
+ scale_colour_brewer(palette="Set1")
>
> p <- ggplot(heightweight, aes(x=sex, y=heightIn))
> p + geom_violin()
> p + geom_violin() + geom_boxplot(width=.1, fill="black", outlier.colour=NA) +
+ stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=2.5)
> p + geom_violin(trim=FALSE)
>
> p + geom_violin(scale="count")
>
> p + geom_violin(adjust=2)
> p + geom_violin(adjust=.5)
> countries2009 <- subset(countries, Year==2009 & healthexp>2000)
> p <- ggplot(countries2009, aes(x=infmortality))
>
> p + geom_dotplot()
`stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
>
> p + geom_dotplot(binwidth=.25) + geom_rug() +
+ scale_y_continuous(breaks=NULL) + # Remove tick markers
+ theme(axis.title.y=element_blank())
> p + geom_dotplot(method="histodot", binwidth=.25) + geom_rug() +
+ scale_y_continuous(breaks=NULL) + theme(axis.title.y=element_blank())
> p + geom_dotplot(binwidth=.25, stackdir="center")
> scale_y_continuous(breaks=NULL) + theme(axis.title.y=element_blank())
Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
> p + geom_dotplot(binwidth=.25, stackdir="centerwhole")
> scale_y_continuous(breaks=NULL) + theme(axis.title.y=element_blank())
Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
>
> ggplot(heightweight, aes(x=sex, y=heightIn)) +
+ geom_dotplot(binaxis="y", binwidth=.5, stackdir="center")
> ggplot(heightweight, aes(x=sex, y=heightIn)) +
+ geom_boxplot(outlier.colour=NA, width=.4) +
+ geom_dotplot(binaxis="y", binwidth=.5, stackdir="center", fill=NA)
> ggplot(heightweight, aes(x=sex, y=heightIn)) +
+ geom_boxplot(aes(x=as.numeric(sex) + .2, group=sex), width=.25) +
+ geom_dotplot(aes(x=as.numeric(sex) - .2, group=sex), binaxis="y",
+ binwidth=.5, stackdir="center") +
+ scale_x_continuous(breaks=1:nlevels(heightweight$sex),
+ labels=levels(heightweight$sex))
>
> library("plot3D", lib.loc="~/R/win-library/3.5")
Warning message:
package ‘plot3D’ was built under R version 3.5.2
> library(plot3D)
> p <- ggplot(faithful, aes(x=eruptions, y=waiting))
>
> p + geom_point() + stat_density3d()
Error in stat_density3d() : could not find function "stat_density3d"
> p + geom_point() + stat_density2d()
> p + stat_density2d(aes(colour=..level..))
> p + stat_density2d(aes(fill=..density..), geom="raster", contour=FALSE)
>
> p + geom_point() +
+ stat_density2d(aes(alpha=..density..), geom="tile", contour=FALSE)
>
> p + stat_density2d(aes(fill=..density..), geom="raster",
+ contour=FALSE, h=c(.5,5))
>
> p <- ggplot(faithful, aes(x=eruptions, y=waiting)) + geom_point()
>
> p + annotate("text", x=3, y=48, label="Group 1") +
+ annotate("text", x=4.5, y=66, label="Group 2")
> p + annotate("text", x=3, y=48, label="Group 1", family="serif",
+ fontface="italic", colour="darkred", size=3) +
+ annotate("text", x=4.5, y=66, label="Group 2", family="serif",
+ fontface="italic", colour="darkred", size=3)
>
> geom_text(x=4.5, y=66, label="Group 2", alpha=.1)
geom_text: parse = FALSE, check_overlap = FALSE, na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity
> p + annotate("text", x=-Inf, y=Inf, label="Upper left", hjust=-.2, vjust=2) +
+ annotate("text", x=mean(range(faithful$eruptions)), y=-Inf, vjust=-0.4,
+ label="Bottom middle")
>
> p <- ggplot(data.frame(x=c(-3,3)), aes(x=x)) + stat_function(fun = dnorm)
>
> p + annotate("text", x=2, y=0.3, parse=TRUE,
+ label="frac(1, sqrt(2 * pi)) * e ^ {-x^2 / 2}")
> p + annotate("text", x=0, y=0.05, parse=TRUE, size=4,
+ label="'Function: ' * y==frac(1, sqrt(2*pi)) * e^{-x^2/2}")
> p <- ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=sex)) + geom_point()
>
> p + geom_hline(yintercept=60) + geom_vline(xintercept=14)
>
> p + geom_abline(intercept=37.4, slope=1.75)
> ggplot(wind, aes(x=DirCat, fill=SpeedCat)) +
+ geom_histogram(binwidth=15, origin=-7.5) +
+ coord_polar() +
+ scale_x_continuous(limits=c(0,360))
Warning messages:
1: `origin` is deprecated. Please use `boundary` instead.
2: Removed 8 rows containing missing values (geom_bar).
> ggplot(wind, aes(x=DirCat, fill=SpeedCat)) +
+ geom_histogram(binwidth=15, origin=-7.5, colour="black", size=.25) +
+ guides(fill=guide_legend(reverse=TRUE)) +
+ coord_polar() +
+ scale_x_continuous(limits=c(0,360), breaks=seq(0, 360, by=45),
+ minor_breaks=seq(0, 360, by=15)) +
+ scale_fill_brewer()
Warning messages:
1: `origin` is deprecated. Please use `boundary` instead.
2: Removed 8 rows containing missing values (geom_bar).
>
> p <- ggplot(md, aes(x=month, y=deaths)) + geom_line() +
+ scale_x_continuous(breaks=1:12)
Error in ggplot(md, aes(x = month, y = deaths)) : object 'md' not found
> md <- ddply(md, "month", summarise, deaths = mean(deaths))
Error in empty(.data) : object 'md' not found
>
> p <- ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
>
> p + theme(axis.title.x=element_text(size=16, lineheight=.9, family="Times",
+ face="bold.italic", colour="red"))
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
> p + ggtitle("Age and Height\nof Schoolchildren") +
+ theme(plot.title=element_text(size=rel(1.5), lineheight=.9, family="Times",
+ face="bold.italic", colour="red"))
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
6: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
7: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
8: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
9: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p + annotate("text", x=15, y=53, label="Some text", size = 7, family="Times",
+ fontface="bold.italic", colour="red")
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
6: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
7: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p + geom_text(aes(label=weightLb), size=4, family="Times", colour="red")
Warning messages:
1: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p + theme_grey(base_size=16, base_family="Times")
Warning messages:
1: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
2: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
6: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
7: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
8: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
9: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
10: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
>
> p <- ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=sex)) + geom_point()
There were 16 warnings (use warnings() to see them)
> p + theme(
+ panel.grid.major = element_line(colour="red"),
+ panel.grid.minor = element_line(colour="red", linetype="dashed", size=0.2),
+ panel.background = element_rect(fill="lightblue"),
+ panel.border = element_rect(colour="blue", fill=NA, size=2))
> p <- ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) + geom_area()
>
> p + scale_fill_discrete()
> p + scale_fill_hue()
>
> p + scale_fill_brewer()
0 Comments