Skip to content

Commit 6405280

Browse files
authored
Update Solutions.R
1 parent 4f693e9 commit 6405280

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

Solutions.R

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,80 @@ your.days<-c(julian(my.days,origin=as.Date("1960-01-01")))
358358
prop.table(margin.table(my.table, 3:1),2)
359359
prop.table(margin.table(my.table, c(1,3)),2)
360360

361+
#### Week 12: ####
362+
# Quiz 1:
363+
packageurl <- "https://mran.revolutionanalytics.com/snapshot/2015-11-30/bin/windows/contrib/3.2/ggplot2_1.0.1.zip"
364+
install.packages(packageurl, repos=NULL, type="source")
365+
library(ggplot2)
366+
367+
qplot(hp, qsec, data=mtcars, geom=c("point","smooth"), method="lm")
368+
369+
# Quiz 2:
370+
##color & facets
371+
372+
# Quiz 3:
373+
p<-gplot(data=mtcars)
374+
p<-p+aes(x=qsec, y=hp)
375+
p<-p+geom_point()+geom_smooth(method=lm)
376+
p
377+
378+
# Quiz 4:
379+
hist(airquality$Temp, breaks=10)
380+
qplot(Temp, data=airquality,binwidth=5)
381+
382+
# Quiz 5:
383+
x<-rnorm(1000, mean=-5)
384+
plot(density(x))
385+
386+
ggplot()+aes(x=x)+geom_density()
387+
qplot(x)
388+
qplot(x, geom = "density")
389+
390+
# Lab 12:
391+
my.data<-data.frame(federal.states=c("Baden-Württemberg","Bayern","Berlin",
392+
"Brandenburg","Bremen","Hamburg","Hessen",
393+
"Mecklenburg-Vorpommern","Niedersachsen",
394+
"Nordrhein-Westfalen","Rheinland-Pfalz",
395+
"Saarland","Sachsen","Sachsen-Anhalt",
396+
"Schleswig-Holstein","Thüringen"),
397+
Population=c(10716644,12691568,3469849,2457872,661888,1762791,
398+
6093888,1599138,7826739,17638098,4011582,989035,4055274,
399+
2235548,2830864,2156759))
400+
401+
# 1:
402+
library(ggplot2)
403+
library(ggmap)
404+
str(my.data$federal.states)
405+
406+
my.data$federal.states<-as.character(my.data$federal.states)
407+
408+
# 2:
409+
latlon <- geocode(my.data$federal.states)
410+
411+
# 3:
412+
my.data$federal.states[1]<-"Baden-Wurttemberg"
413+
my.data$federal.states[16]<-"Thuringen Germany"
414+
415+
# 4:
416+
latlon <- geocode(my.data$federal.states)
417+
View(latlon)
418+
my.data<-cbind(my.data,latlon)
419+
420+
my.data$lon <- latlon$lon
421+
my.data$lat <- latlon$lat
422+
423+
# 5:
424+
Germany <- ggmap(get_map(location="Germany",zoom=6), extent="panel")
425+
426+
## Fixed error
427+
library(devtools)
428+
install_github('ggmap','dkahle')
429+
430+
# 6:
431+
circle_scale<-0.000002
432+
Germany+geom_point(aes(x=lon, y=lat),
433+
data=my.data,
434+
col="red",
435+
alpha=0.4,
436+
size=my.data$Population*circle_scale)
437+

0 commit comments

Comments
 (0)