ggplot2 demo

Author

alper

Published

June 1, 2023

1 Air Quality

Figure 1 further explores the impact of temperature on ozone level.

Code
library(tidyverse)
library(ggplot2)

ggplot(airquality, aes(Temp, Ozone)) + 
  geom_point() + 
  geom_smooth(method = "loess"
)

Figure 1: Temperature and ozone level.

2 mgp data

2.1 mpg scatter plot

Figure 2 shows correlation between highway and city mileages.

Code
ggplot(mpg, aes(hwy, cty, color=cyl)) + 
  geom_point(alpha=0.5, size=2) +
  scale_color_viridis_c() +
  theme_minimal()

Scatterplot of city vs. highway mileage for cars, where points are colored by the number of cylinders. The plot displays a positive, linear, and strong relationship between city and highway mileage, and mileage increases as the number of cylinders decreases.

Figure 2: City and highway mileage for 38 popular models of cars.

2.2 the mpg data as table

There are 234 observations in our data.

Hypothetical table_viewer will show your tables in a much better way.

Code
table_viewer(mpg)

3 Formulas

you can have formulas in your document

\[ price = \hat{\beta}_0 + \hat{\beta}_1 \times area + \epsilon \]

4 Citations

We’re going to do this analysis using literate programming (Knuth 1984).

5 Layout

5.1 Callouts

Note

Here’s some information

References

Knuth, D. E. 1984. “Literate Programming.” The Computer Journal 27 (2): 97–111. https://doi.org/10.1093/comjnl/27.2.97.