Given the following graph:
title <- 'Fuel Economy of Popular Cars'
legend.title <- 'Type of Car'
ggplot(mpg, aes(displ, hwy, color = class)) +
geom_point()
Which are ways that you can change the legend titles? Select all that apply.
scale_color_discrete(name = legend.title)
theme(legend.title = element_text(legend.title))
theme(legend.text = element_text(title = legend.title))
labs(color = legend.title)
Which are ways that you can add a title to your graph? Select all that apply.
labs(title = title)
ggtitle(title)
annotate('text', label = title, x = min(mpg$displ) + 3.5, y = max(mpg$hwy), size = 4)
theme(plot.title = element_text(title))
Create a scatterplot exploring select breakfast cereals1. What is the relationship between cereal ratings and grams of sugar?
sugars_per_oz
that calculates grams of sugars per ounce.geom_point()
with sugars_per_oz
on the x-axis and rating on the y-axisdf_shapes <- data.frame(shape = 0:24)
ggplot(df_shapes, aes(0, 0, shape = shape)) +
geom_point(aes(shape = shape), size = 5, fill = 'red') +
scale_shape_identity() +
facet_wrap(~shape) +
theme_void()
Notice anything interesting with the sugar column in the dataset?
On which shelf can you find the cereal with the highest rating?
geom_text()
for the cereal with the highest ratingCreate a bar graph of cities & towns with the greatest nominal growth between 2010 and 2020 like the one below…
Using ofm_april1_population_final_tidied.xlsx
…
dcast()
function from the reshape2
package:
reshape2::dcast(<your data frame>, County + Jurisdiction ~ paste0("Year_", Year_chr), value.var = "Estimate")
head()
)Jurisdiction
column to a factorreorder()
Data Source: https://www.kaggle.com/crawford/80-cereals, gathered and cleaned up by Petra Isenberg, Pierre Dragicevic and Yvonne Jansen. Original source can be found here↩︎