Below are the solutions to these exercises on visualizations with ggvis.
#################### # # # Exercise 1 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) plot1 <- ggvis(Cars93, x = ~Horsepower, y = ~MPG.city) #################### # # # Exercise 2 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) plot1 <- ggvis(Cars93, x = ~Horsepower, y = ~MPG.city) layer_points(plot1) #################### # # # Exercise 3 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(x = ~Horsepower, y = ~MPG.city) %>% layer_points() #################### # # # Exercise 4 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(~Horsepower, ~MPG.city, stroke = ~Cylinders) %>% layer_points() #################### # # # Exercise 5 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(~Horsepower, ~MPG.city, fill = ~Cylinders) %>% layer_points() #################### # # # Exercise 6 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(~Horsepower, ~MPG.city, size = ~EngineSize) %>% layer_points() #################### # # # Exercise 7 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(~Horsepower, ~MPG.city, shape = ~factor(Cylinders)) %>% layer_points() #################### # # # Exercise 8 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(~Horsepower, ~MPG.city, fill := "red", stroke := "black") %>% layer_points() #################### # # # Exercise 9 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(~Horsepower, ~MPG.city, size := 300, opacity := 0.5) %>% layer_points() #################### # # # Exercise 10 # # # #################### library(ggvis) library(MASS) library(magrittr) attach(Cars93) Cars93 %>% ggvis(~Horsepower, ~MPG.city, shape := "cross") %>% layer_points()
Leave a Reply