By the end of class, you should be able to
The first part is a written report (using R Markdown) that presents and analyzes the data.
Report Requirements/Components:
Use geom_polygon to draw shapes.
rect <- data.frame(x_coords = c(3, 5, 5, 3),
y_coords = c(4, 4, 2, 2))
ggplot(data = rect) +
geom_polygon(aes(x = x_coords, y = y_coords))
Draw multiple polygons by grouping points.
double_rect <- data.frame(x_coords = c(1,2,2,1, 3,4,4,3),
y_coords = c(2,2,1,1, 2,2,1,1),
rect_num = c(1,1,1,1, 2,2,2,2))
ggplot(data = double_rect) +
geom_polygon(aes(x = x_coords, y = y_coords, group = rect_num))
each row is a corner point
which rect the point goes with
ggplot2 provides a set of data frames (from the included
maps
library) which include polygon definitions for different geographic maps.
Access these data frames with the
map_data()
function.
# access library
library("maps")
# load the data
usa_states <- map_data("state")
# plot the polygons
ggplot(data = usa_states) +
geom_polygon(aes(x = long, y = lat, group = group)) +
coord_quickmap() # map coordinate system!
Leaflet is an R package (library) that provides functions for building interactive maps.
install.packages("leaflet") # once per machine
library("leaflet") # in each relevant script
# Create a new map and add a layer of map tiles from CartoDB
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
# center the map on Seattle
setView(lng = -122.3321, lat = 47.6062, zoom = 10) %>%
# add a marker
addMarkers(lng = -12.3110, lat = 47.6594, popup="Go Huskies!")
x-position
y-position
size
color
A way of classifying the nature of data values. Applies to all data analysis, distinct from the R "data type".
Level |
Example |
Operations |
---|---|---|
Nominal
|
Fruits: apples, bananas, oranges, etc. |
== !=
|
Ordinal
|
Hotel rating: 5-star, 4-star, etc. |
== != < >
|
Interval (Quantitative) |
Dates: 05/15/2012, 04/17/2015, etc. |
== != < > + – "3 units bigger" |
Ratio (Quantitative) ordered, fixed "zero" can find magnitude |
Lengths: 1 inch, 1.5 inches, 2 inches, etc. |
== != < >
|
(Mackinlay, 1986)
Resemblance (nominal)
(A != B != C)
Order (ordinal)
(B is between A and C)
Proportion (quantitative)
(BC is 2x long as AB)
We can describe colors in terms of:
Hue (red, yellow, green, etc)
Saturation
(vivid vs. washed out)
Brightness or Value
(luminance)
Hue is good for categorical (nominal) data
Saturation and Brightness are good for continuous (ordinal or ratio) data
Hue (categorical)
Saturation (continuous)
A
B
A
B
(Kabada et al. 2007)
(Mackinlay, 1986)
Assignment 6 (visualization) due Thursday
Ask if there are questions!
Next: Multi-player git