Data Visualization
- Use a geom to represent data points, use the geom’s aesthetic properties to represent variables. Each function returns a layer.
One Variable
with ggplot2
Two Variables
Continuous
Cheat Sheet
Continuous X, Continuous Y f <- ggplot(mpg, aes(cty, hwy))
a <- ggplot(mpg, aes(hwy))
with ggplot2
Cheat Sheet
Data Visualization
Basics
i + geom_bin2d(binwidth = c(5, 0.5))
f + geom_blank()
a + geom_area(stat = "bin")
Data Visualization
Continuous Bivariate Distribution i <- ggplot(movies, aes(year, rating)) xmax, xmin, ymax, ymin, alpha, color, fill, linetype, size, weight
Geomsx,-y,Usealpha, a geomcolor, to represent data points,size use the geom’s aesthetic properties to represent variables fill, linetype,
One Variableb + geom_area(aes(y = ..density..), stat = "bin")
Continuous
a+
i + geom_density2d()
Two Variables f + geom_jitter()
X, Continuous Y
Continuous Bivariate Distribution
= "gaussian")
Geoms geom_density(kernel
- Use a geom to represent Continuous data points, use the geom’s aesthetic properties to represent variables x, y, alpha, color, fill, shape, size h <ggplot(movies, aes(year, rating)) f <- ggplot(mpg, aes(cty, hwy))
x, y, alpha, color, fill, linetype, size, weight f + geom_blank()
One Variable
Two Variablesh + geom_bin2d(binwidth = c(5, 0.5)) a + geom_area(stat
= "bin") with ggplot2 xmin, ymax, ymin, alpha, color, fill, b + geom_density(aes(y =
..county..))
f xmax,
+ geom_point()
Continuous X, Continuous Y
Continuous
x, y, alpha, Continuous color, fill, linetype, size linetype, size,Bivariate weight Distribution ggplot2 is based on the grammar h <- ggplot(movies, aes(year, rating)) f <- ggplot(mpg, aes(cty, hwy))
Cheat
Sheet of graphics, the b + geom_area(aes(y
=
..density..), stat =
"bin")
a <- ggplot(mpg, aes(hwy)) a + geom_dotplot() f + geom_jitter() h + x, geom_density2d() y, alpha, color, fill, shape, size idea that you can build every graph from the same a + geom_density(kernal = "gaussian")