A New Week!



We aren’t computer scientists and that’s okay!

We make lots of mistakes. Mistakes are funny. You can laugh with us.

Let’s go, Simba, Pumbaa, and Timon!





1 More data type: factor


Factors are categorical variables that can be either numeric or character.

They can be ordered and are very useful for statistical analysis and for plotting.

You use factor() to create a factor object

2 Plots with ggplot2




In data analysis, it’s super important to visualize your data early and often.

ggplot2 is a plotting package that makes it simple to create complex plots from data frame.









A ggplot has 3 ingredients: base, aesthetics, and layers


2.1 The base plot

We load the package of ggplot2, but the function to make the plot is only ggplot(). No 2.


2.2 The X, Y aesthetics

The aesthetics assign the columns from the data that you want to use in the chart. This is where you set the X-Y variables that determine the dimensions of the plot.

2.5 Save plots

You’ve made some plots you can be proud of, so let’s learn to save them so we can cherish them forever. There’s a function called ggsave to do just that. How do we ggsave our plots?

Exercise

Try to make a plot showing the daily ozone in August 2016 at sites 27-137-7001 and 27-137-7554 using the “ozone_samples_demo.csv” file


3 Recap



  • factor

  • ggplot()