library(tidyverse)
#Load datasets we will use for the lecture source(here::here("code", "healthcare.R")) #loads dataset-specific variables
heart
Below is an example of the most basic form of the ggplot code
ggplot(data)+ #this will generate a blank plot for your data. At this point, ggplot knows what to plot, but not how. geom(mapping=aes(x, y)) #adding a geom tells ggplot how you would like to map your data
Use this template to make a simple ggplot.
heart
dataset, Next, fit a smooth line (linear regression) to these points
*by adding another geom
and specifying the argument method = "lm"
Next, color by whether the patient has exercise-induced angina
The last plot probably has your color based on a continuous scale; now change color by sex (a discrete variable)
Next, fix the labels to capitalize, and be more informative
Next, give the plot a title, by calling title = "title"
within labs
And give the plot a caption, by calling caption = "Plot by YOURNAME"
within labs
Next, use facet_grid
to split this graph based on whether the pateint has exercise induced angina or not. Make sure to wrap your variable in factor()
to convert the numeric into a factor variable.
Next, change the theme to light
Lastly, save the object as a png image using ggsave
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.