Environmental Data Analysis and Visualization
Learning how to look
University of Wollongong
Getting a clearer view
ggplot(data=Sacramento,aes(x=city,y=price)) +
geom_boxplot()
Getting a clearer view
Flip x and y axes
ggplot(data=Sacramento,aes(x=city,y=price)) +
geom_boxplot() +
coord_flip()
Getting a clearer view
Resize axis labels
Getting a clearer view
Reorder based on median house prices
Getting a clearer view
Getting a clearer view
Getting a clearer view
ggplot(data=abalone,aes(x=diameter*200,y=weight.whole*200)) +
geom_point()
Getting a clearer view
Changing the transparency (alpha)
ggplot(data=abalone,aes(x=diameter*200,y=weight.whole*200)) +
geom_point(alpha=0.1)
Getting a clearer view
Changing the size
ggplot(data=abalone,aes(x=diameter*200,y=weight.whole*200)) +
geom_point(size=0.1)
Getting a clearer view
Binning the values (geom_bin2d
)
ggplot(data=abalone,aes(x=diameter*200,y=weight.whole*200)) +
geom_bin2d()
Getting a clearer view
Binning the values (geom_hex
)
ggplot(data=abalone,aes(x=diameter*200,y=weight.whole*200)) +
geom_hex()
Getting a clearer view
Getting a clearer view
ggplot(data=drop_na(bully,maxl),aes(x=altitude,y=maxl)) +
geom_point()
Getting a clearer view
Zooming in
ggplot(data=drop_na(bully,maxl),aes(x=altitude,y=maxl)) +
geom_point() +
coord_cartesian(xlim=c(0,100))
Getting a clearer view
ggplot(data=drop_na(bully,maxl),aes(x=altitude,y=maxl)) +
geom_point()
Getting a clearer view
Natural log transformation on x-axis
ggplot(data=drop_na(bully,maxl),aes(x=altitude,y=maxl)) +
geom_point() +
scale_x_continuous(trans='log')
Getting a clearer view
Log-10 transformation on x-axis
ggplot(data=drop_na(bully,maxl),aes(x=altitude,y=maxl)) +
geom_point() +
scale_x_continuous(trans='log10')
Getting a clearer view
Add a smooth line
ggplot(data=drop_na(bully,maxl),aes(x=altitude,y=maxl)) +
geom_point() +
scale_x_continuous(trans='log10')+
geom_smooth()
Seeing the bigger picture
Faceted plots can help us view the same pattern across multiple variables.
ggplot(data=Sacramento,aes(x=sqft,y=price)) +
geom_point() +
facet_wrap(vars(type))
Activity: Looking and comparing
In this exercise, you’ll use the scat
dataset in the modeldata
package (same data, fewer bobcars)
Use the facet_wrap
function to look at relationships (remember to use the vars
function to identify your aesthetic mapping):
length and diameter by species
diameter and mass by species
length and mass by month
one additional combination of your choice