Lab 1D
Directions: Follow along with the slides and answer the questions in red font in your journal.
food
.dotPlot()
function to create a dotPlot
of the amount of sugar
in our food
data.
dotPlot
is exactly like you'd use to make a histogram
.dotPlot
.dotPlot
in two by faceting on our observations' salty/sweet variable.
layout
option in our dotPlot
function.
dotPlot
split by salty_sweet
layout = c(1,2)
bargraph
function. Use a similar syntax to add the layout
option to the dotPlot
function.food
data based on people who ate Salty
snacks:food_salty <- filter(____ , ____ == "Salty")
food_salty
and write down the number of observations in it. Then use the subset data to make a dotPlot of the sodium
in our Salty
snacks.food_salty <- filter(____ , ____ == "Salty")
filter()
tells R that we're going to look at only the values in our data that follow a rule.salty_sweet == "Salty"
is the rule to follow.salty_sweet == "Salty"
, into 3 parts:
salty_sweet
, is the particular variable we want to use to select our subset."Salty"
, is the value of the variable that we want to select. We only want to see data with the value Salty
for the variable salty_sweet
.==
describes how we want to relate our variable (salty_sweet
) to our value ("Salty"
). In this case, we want values of salty_sweet
that are exactly equal to "Salty"
.head()
function to help us see what's happening when we write salty_sweet == "Salty"
.
head()
returns the values of the first 6 observations.tail()
function returns the last 6 observations.head(~salty_sweet == "Salty", data = food)
TRUE
and FALSE
tell us about how our rule applies to the first six snacks in our data? Which of the first six observations were Salty
?food_salty <- filter(____ , ____ == "Salty")
food_salty <- filter(____ , ____ == "Salty")
food_salty
.food_salty
to do anything we could do with the regular food
data …
Salty
.food
data based on the food being salty AND costing less than 2 dollars.my_sub <- filter(food , salty_sweet == "Salty", cost <= 2)
View
the my_sub
data we filtered in the above line of code and verify that it only includes salty snacks that cost less than 2 dollars.dotPlot
to answer each of the following questions:
healthy_level < 3
and when healthy_level > 3
?dotPlots
and histograms
.
nint
option. For instance, to have a plot with 3 bins, use nint = 3
. To have a plot with 30 bins, use nint = 30
.