R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and Microsoft Word documents. For ANT 191, we’ll use R Markdown to generate HTML content. In other words, to create web pages.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

iris[1:10, ]
##    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1           5.1         3.5          1.4         0.2  setosa
## 2           4.9         3.0          1.4         0.2  setosa
## 3           4.7         3.2          1.3         0.2  setosa
## 4           4.6         3.1          1.5         0.2  setosa
## 5           5.0         3.6          1.4         0.2  setosa
## 6           5.4         3.9          1.7         0.4  setosa
## 7           4.6         3.4          1.4         0.3  setosa
## 8           5.0         3.4          1.5         0.2  setosa
## 9           4.4         2.9          1.4         0.2  setosa
## 10          4.9         3.1          1.5         0.1  setosa

If you only want your final document to include the result of an R command (but not the R code chunk):

For more information about R Markdown, click here.

Now let’s create our first interactive graph

We first need to install and load a new R package:

# install the plotly package
install.packages("plotly")

# load the plotly package:
library(plotly)

And now let’s plot iris data:

library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
p1 <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, 
    color = ~Species)
p1
## No trace type specified:
##   Based on info supplied, a 'scatter' trace seems appropriate.
##   Read more about this trace type -> https://plot.ly/r/reference/#scatter
## No scatter mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode

What about creating a 3-D interactive plot?

p2 <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width, 
    z = ~Petal.Length, color = ~Species, symbols = c(0, 1), type = "scatter3d", 
    mode = "markers")
p2

Now try to customize your interactive graphs using this resource: https://plot.ly/r/line-and-scatter/