Overview: This document addresses the Week 3 assignment of the Data Products Coursera class. For this assignment, I’ve used the “morley” data from the “datasets” package which describes a set of experiments conducted at the end of the 19th century to measure the speed of light in several different medium.
Today’s date:
## [1] "2018-12-01"
The classical data of Michaelson and Morley on the speed of light. The data consists of five experiments, each consisting of 20 consecutive ‘runs’. The response is the speed of light measurement, suitably coded.
library(plotly, quietly = TRUE, warn.conflicts = FALSE)
library(ggplot2, quietly = TRUE, warn.conflicts = FALSE)
library(datasets)
head(morley)
## Expt Run Speed
## 001 1 1 850
## 002 1 2 740
## 003 1 3 900
## 004 1 4 1070
## 005 1 5 930
## 006 1 6 850
Below I’ve created a plot using ggplot2 and used the appropriate function to convert the plot to plot_ly.
mor_ley <- morley
p<- ggplot(data = mor_ley, aes(x = Run, y = Speed)) +
geom_point(size =4)
p<- p+geom_smooth(aes(colour = as.factor(Expt), fill = as.factor(Expt) )) + facet_wrap(~Expt)
p<- p+labs(title = "Morley Speed of Light Experiment", x = "Run", y = "Speed")
p <- ggplotly(p)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
p
Here is a second plot, using the plotly syntax rather than converting from ggplot.
plot_ly( mor_ley, x = mor_ley$Run, y = mor_ley$Speed, type = "scatter", mode = "lines", color = as.factor(mor_ley$Expt) )%>%
layout(title = "Morley's Speed of Light Experiments",
xaxis = list(title = "Run"),
yaxis = list (title = "Speed of light")
)