Forked from amitkaps/Multi Variable Visualization
Last active
August 29, 2015 14:20
-
-
Save jamesballard/1c0ec9129fda45fe7162 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
?mpg | |
head(mpg) | |
str(mpg) | |
# Identify a scatter point | |
attach(mtcars) | |
plot(mpg, wt) | |
identify(x = mpg, y = wt, n = 3, label = row.names(mtcars)) | |
detach(mtcars) | |
# Two Variables Viz | |
ggplot(mpg, aes(class, hwy)) + geom_point() | |
ggplot(mpg, aes(class, hwy)) + geom_jitter() | |
ggplot(mpg, aes(reorder(class, hwy), hwy)) + geom_point() | |
ggplot(mpg, aes(displ, hwy)) + geom_point() | |
# Three Variables Viz - Color (Cat., Cont.) | |
ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() | |
ggplot(mpg, aes(displ, hwy, colour = cyl)) + geom_point() | |
# Three Variables Viz - Size (Cat, Cont.) | |
ggplot(mpg, aes(displ, hwy, size = drv)) + geom_point() | |
ggplot(mpg, aes(displ, hwy, size = cyl)) + geom_point() | |
# Three Variables Viz - Shape (Cat) | |
ggplot(mpg, aes(displ, hwy, shape = drv)) + geom_point() | |
# Four Variables Viz - Combine Color, Shape & Size | |
ggplot(mpg, aes(displ, hwy, color = class, shape = drv)) + geom_point() | |
ggplot(mpg, aes(displ, hwy, color = class, size = drv)) + geom_point() | |
# Four - Six Variable Viz - Facetting + Color, Shape, Size | |
ggplot(mpg, aes(displ, hwy, color = class)) + geom_point() + facet_wrap(~ cyl) | |
ggplot(mpg, aes(displ, hwy, color = class)) + geom_point() + facet_grid(~ cyl) | |
ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_grid(drv ~ cyl) | |
ggplot(mpg, aes(displ, hwy, color = class)) + geom_point() + facet_grid(drv ~ cyl) | |
ggplot(mpg, aes(displ, hwy, color = class, size = trans)) + | |
geom_point() + facet_grid(drv ~ cyl) | |
ggplot(mpg, aes(displ, hwy, color = class, size = trans)) + | |
geom_point(alpha = 0.4) + facet_grid(drv ~ cyl) | |
# More than Three - Matrices (SPLOM, GGally) | |
plot(mpg) | |
plot(iris) | |
library(GGally) | |
mpg_select <- subset(mpg, select = c(displ, hwy, drv)) | |
plot(mpg_select) | |
ggpairs(mpg_select) | |
ggpairs(mpg_select, diag = list(continuous = "bar", discrete = "bar"), | |
axisLabels = 'show') | |
ggpairs(mpg_select, diag = list(continuous = "bar", discrete = "bar"), | |
upper = list(continuous = "density", combo = "dot"), | |
axisLabels = 'show') | |
# More than Three - Parallel Coordinates | |
ggparcoord(mpg, column = c(1:11), groupColumn = 4) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment