diff --git a/class-activity-3.Rmd b/class-activity-3.Rmd index d8dd1d6..667d662 100644 --- a/class-activity-3.Rmd +++ b/class-activity-3.Rmd @@ -1,13 +1,13 @@ --- title: "class activity 3" -author: "Charles Lang" +author: "Ziyuan Guo" date: "10/2/2018" output: html_document --- #Mapping aesthetic to data to = layer ```{r} -install.packages("ggplot2") +#install.packages("ggplot2") library(ggplot2) ggplot(diamonds, aes(x = price, y = carat)) + @@ -43,13 +43,16 @@ ggplot(mpg, aes(displ, hwy, color = class)) + Can you create a line graph using the "economics_long" data set that shows change over time in "value01" for different categories of "variable"? ```{r} - +economics_long +ggplot(economics_long, aes(date,value01)) + geom_point() + facet_wrap(~variable) +ggplot(economics_long, aes(date,value01, color = variable)) + geom_point() ``` If you would like to recreate the Minard graphic of Napoleon's Troops the code is below and the data is in this repo. ```{r} - +cities <- read.csv("~/class-activity-3/cities.txt", sep="") +troops <- read.csv("~/class-activity-3/troops.txt", sep="") ggplot(cities, aes(long, lat)) + geom_path(aes(size = survivors, colour = direction, @@ -61,7 +64,8 @@ size = 4) last_plot() + scale_x_continuous("", limits = c(24, 39)) + scale_y_continuous("") + - scale_colour_manual(values = c("grey50","red")) + - scale_size(to = c(1, 10)) + scale_colour_manual(values = c("grey50","red")) + # + + # scale_size(to = c(1, 10)) ``` diff --git a/class-activity-3.html b/class-activity-3.html new file mode 100644 index 0000000..b5cf3c9 --- /dev/null +++ b/class-activity-3.html @@ -0,0 +1,488 @@ + + + + + + + + + + + + + + + +class activity 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +

#Mapping aesthetic to data to = layer

+
#install.packages("ggplot2")
+library(ggplot2)
+
+ggplot(diamonds, aes(x = price, y = carat)) +
+  geom_point()
+

+

#Two layers

+
ggplot(mpg, aes(reorder(class, hwy), hwy)) +
+  geom_jitter() +
+  geom_boxplot()
+

+
#Plot count
+ggplot(diamonds, aes(depth)) +
+  geom_histogram(aes(y = ..count..), binwidth=0.2) +
+  facet_wrap(~ cut) + xlim(50, 70)
+
## Warning: Removed 26 rows containing non-finite values (stat_bin).
+
## Warning: Removed 10 rows containing missing values (geom_bar).
+

+
#Plot density
+ggplot(diamonds, aes(depth)) +
+  geom_histogram(aes(y = ..density..), binwidth=0.2) +
+  facet_wrap(~ cut) + xlim(50, 70)
+
## Warning: Removed 26 rows containing non-finite values (stat_bin).
+
+## Warning: Removed 10 rows containing missing values (geom_bar).
+

+
ggplot(mpg, aes(displ, hwy, color = class)) +
+  geom_point()
+

+

Can you create a line graph using the “economics_long” data set that shows change over time in “value01” for different categories of “variable”?

+
economics_long
+
## # A tibble: 2,870 x 4
+##    date       variable value  value01
+##    <date>     <chr>    <dbl>    <dbl>
+##  1 1967-07-01 pce       507. 0       
+##  2 1967-08-01 pce       510. 0.000265
+##  3 1967-09-01 pce       516. 0.000762
+##  4 1967-10-01 pce       512. 0.000471
+##  5 1967-11-01 pce       517. 0.000916
+##  6 1967-12-01 pce       525. 0.00157 
+##  7 1968-01-01 pce       531. 0.00207 
+##  8 1968-02-01 pce       534. 0.00230 
+##  9 1968-03-01 pce       544. 0.00322 
+## 10 1968-04-01 pce       544  0.00319 
+## # ... with 2,860 more rows
+
ggplot(economics_long, aes(date,value01)) + geom_point() + facet_wrap(~variable) 
+

+
ggplot(economics_long, aes(date,value01, color = variable)) + geom_point()
+

+

If you would like to recreate the Minard graphic of Napoleon’s Troops the code is below and the data is in this repo.

+
cities <- read.csv("~/class-activity-3/cities.txt", sep="")
+troops <- read.csv("~/class-activity-3/troops.txt", sep="")
+ggplot(cities, aes(long, lat)) +
+  geom_path(aes(size = survivors, colour =
+direction,
+    group = interaction(group, direction)), data =
+troops) +
+  geom_text(aes(label = city), hjust = 0, vjust = 1,
+size = 4)
+

+
# Polish appearance
+last_plot() +
+  scale_x_continuous("", limits = c(24, 39)) +
+  scale_y_continuous("") +
+  scale_colour_manual(values = c("grey50","red"))
+

+
  # +
+  # scale_size(to = c(1, 10))
+ + + + +
+ + + + + + + + + + + + + + +