forked from UserR-Burlington/Superfoods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
superfoods_gamestorm.Rmd
68 lines (50 loc) · 2.19 KB
/
superfoods_gamestorm.Rmd
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
Gamestorm re-analysis of Superfoods data set
================================================
Script to explore, reanalyze and depict Superfoods data.
Originally shown at [http://www.informationisbeautiful.net/visualizations/snake-oil-superfoods/]
and data available [publically](https://docs.google.com/spreadsheet/ccc?key=0Aqe2P9sYhZ2ndHdORGgxdl9xbzJ1enJJNVc5cDFJWXc#gid=2).
```{r opts}
#library(RCurl)
library(knitr)
library(ggplot2)
```
Load data.
Method 1. Download from Google Docs (copy of original file in csv format) following this [guide](http://blog.revolutionanalytics.com/2009/09/how-to-use-a-google-spreadsheet-as-data-in-r.html) from our sponsor.
Method 2. Standard read.csv
For both, skip metadata rows then import row 2 as header.
```{r loaddata}
# read data
# skip first 3 rows, then import first row as header
superfoods <- read.csv("Superfood.csv", skip = 3, header = FALSE)
superfoods_header <- read.csv("Superfood.csv", skip = 1, nrow = 1, header = FALSE, stringsAsFactors = FALSE)
colnames(superfoods) <- superfoods_header
# For a challenge, download data from GoogleDocs using RCurl
# skip first 3 rows, then import first row as header
#myCSV <- getURL("https://docs.google.com/spreadsheet/pub?key=0Ar5IymziRJ_9dDl1aTdSRlZKakpnNXVjT2ZmVzdaQ1E&single=true&gid=2&output=csv")
#superfoods <- read.csv(textConnection(myCSV), skip = 3, header = FALSE, stringsAsFactors = FALSE)
#dim(superfoods)
#superfoods_header <- read.csv(textConnection(myCSV), nrows = 1, stringsAsFactors = FALSE)
#colnames(superfoods) <- superfoods_header
```
Examine datafile. Subset to relevant colums.
```{r explore}
dim(superfoods)
superfoods[1:5,1:10]
superfoods[1:5,11:20]
superdata <- superfoods[ , c("Food", "alternative name", "EVIDENCE", "condition", "HEALTH CONDITION", "TYPE", "One to watch", "POPULARITY", "NO OF STUDIES WE EXAMINED", "SCIENTIFIC INTEREST")]
str(superdata)
```
Plot
```{r, fig.align='center'}
# base plot
barplot(superdata$EVIDENCE)
# point plot
p <- ggplot(superdata, aes(Food, EVIDENCE))
p + geom_point()
p <- ggplot(superdata, aes(EVIDENCE, Food))
p + geom_point()
```
```{r close}
sessionInfo()
purl("superfoods_gamestorm.Rmd")
```