Source file ⇒ R1.Rmd
ggplot
(see DataCamp DataVisualization with ggplot2 course) –do first four chaptersInstall DataComputing on your computer:
install.packages("devtools")
devtools::install_github("DataComputing/DataComputing")
Most important data structures are vectors and data tables.
ggplot2 is a grpahics package that uses the components of graphs (i.e. glyphs, aestetics, frames, scales, layers) –called the grammar of graphics.
Here is the data table mosaicData::CPS85:
frame <- CPS85 %>% ggplot(aes(x=age,y=wage))
frame + geom_point()
frame <- CPS85 %>% ggplot(aes(x=age,y=wage))
frame + geom_point(aes(shape=sex))
frame <- CPS85 %>% ggplot(aes(x=age,y=wage))
frame + geom_point(aes(shape=sex)) + facet_grid(married ~ .)
frame <- CPS85 %>% ggplot(aes(x=age,y=wage))
frame + geom_point(aes(shape=married)) + ylim(0,30)
BabyNames %>%
group_by(name) %>%
summarise(tot=sum(count)) %>%
arrange(desc(tot)) %>%
head(3)
name | tot |
---|---|
James | 5114325 |
John | 5095590 |
Robert | 4809858 |
Here is a cheet sheet: (Rstudio)[https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf]
It is important to be able to look up the syntax and aesetics for the different geoms. Here is a good resourse from ggplot2.org
Please make
CPS85 %>% ggplot(aes(x=age,wage)) + geom_point(aes(color=married)) + facet_wrap(~sex)