# Load the ggvis package
library(ggvis)
## Warning: package 'ggvis' was built under R version 3.2.5
# Change the code below to plot the disp variable of mtcars on the x axis
mtcars %>% ggvis(~disp, ~mpg) %>% layer_points()
# Change the code below to make a graph with red points
mtcars %>% ggvis(~wt, ~mpg, fill := "red") %>% layer_points()
# Change the code below draw smooths instead of points
mtcars %>% ggvis(~wt, ~mpg) %>% layer_smooths()
# Change the code below to make a graph containing both points and a smoothed summary line
mtcars %>% ggvis(~wt, ~mpg) %>% layer_points() %>% layer_smooths()
Every ggvis graph contains 4 essential components: data, a coordinate system, marks and corresponding properties
faithful %>%
ggvis(~waiting, ~eruptions, fill := "red") %>%
layer_points() %>%
add_axis("y", title = "Duration of eruption (m)",
values = c(2, 3, 4, 5), subdivide = 9) %>%
add_axis("x", title = "Time since previous eruption (m)")
pressure <- read.csv("pressure.csv")
head(pressure)
## temperature pressure
## 1 0 0.0002
## 2 20 0.0012
## 3 40 0.0060
## 4 60 0.0300
## 5 80 0.0900
## 6 100 0.2700
# Adapt the code: show bars instead of points
pressure %>% ggvis(~temperature, ~pressure) %>% layer_bars()
# Adapt the codee: show lines instead of points
pressure %>% ggvis(~temperature, ~pressure) %>% layer_lines()
fill property of your scatterplot to the temperature variable. Use ~!size property of your scatterplot to the to the pressure variable.# Extend the code: map the fill property to the temperature variable
pressure %>% ggvis(~temperature, ~pressure, fill = ~temperature) %>% layer_points()
# Extend the code: map the size property to the pressure variable
pressure %>% ggvis(~temperature, ~pressure, size = ~pressure) %>% layer_points()