library(dplyr) library(grid) cars12 <- read.csv("data/cars12.csv") # # cars <- read.csv("cars.csv") # cars12 <- cars %>% filter(Year == 2012) # # write.csv(cars12, file = "cars12.csv") library(loon) lp1 <- with(cars12, l_plot(x = Torque, y = City.mpg, title = "2012 cars", linkingGroup = "2012 cars", itemLabel = paste0( "Name:", ID, "\n", "Driveline:", Driveline, "\n", "Height:", Height, "\n", "Width:", Width, "\n", "Length:", Length), showLabels = TRUE) ) lh1 <- with(cars12, l_hist(x = Horsepower, yshows = "density", showScales = TRUE, showLabels = TRUE, showGuides = TRUE) ) d <- density(cars12$Torque, bw = "sj", adjust = 3) l_layer.density(lh1, d, color="steelblue", linewidth=3) # add layer l_scaleto_world(lh1) # scale to world lp1["color"] <- cars12$Number.of.Forward.Gears p3d <- with(l_scale3D(cars12), l_plot3D(City.mpg, Torque, Horsepower, showGuides = TRUE, linkingGroup = "2012 cars")) Vars <- c("City.mpg", "Highway.mpg", "Height", "Length", "Width") l_pairs(cars12[, Vars], showHistograms = TRUE, linkingGroup = "2012 cars") ## Aesthetic # size lp1['size'] <- 6 # color fuelType <- as.character(unique(cars12$Fuel.Type)) cols <- c("lightblue", "steelblue", "blue") for(i in 1:length(fuelType)) { lp1['color'][cars12$Fuel.Type == fuelType[i]] <- cols[i] } # glyph lp1['glyph'][which(cars12$Classification == "Automatic transmission")] <- "ctriangle" lp1['glyph'][which(cars12$Classification == "Manual transmission")] <- "ccircle" ## Scaling # only show 'Diesel fuel cars' lp1['active'] <- lp1['color'] == l_hexcolor("blue") l_scaleto_active(lp1) lp1["title"] <- "Diesel fuel cars" # show all of them lp1["active"] <- TRUE l_scaleto_plot(lp1) lp1["title"] <- "All points again" # linking l_configure(lp1, linkingGroup = "cars12", sync = "push") l_configure(lh1, linkingGroup = "cars12", sync = "push") ##### # # ggplot # library(ggplot2) p1 <- ggplot(cars12, mapping = aes(x = Horsepower, y = City.mpg)) + geom_point() p1 p2 <- ggplot(cars12, aes(x = Torque, y = Horsepower, color = Driveline)) + geom_point() + geom_smooth() + facet_wrap(~Driveline) p2