ggplot
Andy Grogan-Kaylor
2022-10-27
b
to make text bigger. Press
s
to make text smaller.These are simulated data designed to be similar to the data that might come from a social service agency.
The data contain the following (simulated) variables:
ID
, age
, gender
,
race_ethnicity
, family_income
,
program
, mental_health_T1
,
mental_health_T2
, latitude
,
longitude
.
The mental health variables are scaled to have an average of 100. Lower numbers indicate lower mental health, while higher numbers indicate higher mental health.
There are some differences in mental health status in the data and an interesting exercise could be to use software like Excel, Google Sheets, Tableau or R to try to see which factors predict these differences.
ggplot
aes
theticgeom
etrye.g. U.N. Blue.
Here the use of color adds aesthetic appeal. We do this by
placing fill
and color
in the
geom
etry.
Compare the minimal and maximal philosophies.
Here, we place fill
color in the aes
thetic
so that color adds additional information, i.e. the gender of
respondents.
(We still retain color
in the geom
to
govern outline color)
viridis
color palette
facet_wrap()
ggplot(clients,
aes(x = program,
fill = gender, # color as `information`
y = mental_health_T2)) +
stat_dots(color = "black") + # dotplot geometry
scale_fill_viridis_d() +
coord_flip() +
labs(title = "Program Enrollment",
subtitle = "By Gender Identity",
caption = "Higher Mental Health Scores Are Better",
y = "Mental Health At Time 2",
x = "Program") +
theme_minimal() +
theme(plot.title = element_text(size = rel(1.5),
color = "darkblue"))