Académique Documents
Professionnel Documents
Culture Documents
3. How many variables were used to create this plot? Which variables were used and how were
they used? 3 variables were used in the data set below. Male, Female, and height were used
in the data set and they were used to compare heights and separate them by gender.
Scatterplots
4. Describe in your own words what a scatterplot looks like. A graph where two variables are
plotted along two axes, the organization is not well to understand, but the two variable that are in
the chart are all scattered.
Creating Scatterplots
Scatterplots in action
7. Use a scatterplot to answer the following question: Do snacks that have more calories also
have more total_fat? Why do you think that?
a) What code did you use to create the scatterplot? xyplot(total_fat~calories, data=
food)
b) Paste the scatterplot here:
c) Answer the original question. Snacks that have more calories do have more total fat. I
think this because the data set shows this by the calories and total fat being so clustered
together.
d) What happens if you swap the calories and total_fat variables in your code? Does the
relationship between the variables change? The relationship does not change the calories
and total fat are still clustered together in the same area.
e) Does the relationship between calories and total_fat change when the snack is either Salty
or Sweet? Write down the code you used to answer this question. The answer does not
change in the chart. The total fat and calories os still clustered in the same area even
though the food was salty or sweet. The code I used was
xyplot(total_fat~calories|salty_sweet, data= food ).
load_lab( )
5
4-variable scatterplots
8. How can we change the color of the points in a scatterplot? You add the groups argument.
9. Create a scatterplot that uses these 4 variables: sodium, sugar, healthy_level, salty_sweet.
a) What code did you use?xyplot(sodium+sugar~healthy_level+salty_sweet,data=food)
b) Paste the scatterplot here:
Multiple facets
10. How do you modify a code to facet by two variables instead of just one? By splitting the the data
using 2 facets can give us additional insights that might otherwise be hidden.
11. How does the healthy_level of a Salty or Sweet snack impact the number of calories in the
snack?
a) What is the code that you used to create a plot?histogram(~calories|healthy_level+salty_sweet,
data = food)
b) Paste the plot here:
c) Answer the question. If the snack were to have a low healthy level it may have a higher
amount of sugar and sodium and if the healthy level were higher it would have less
sodium and sugar.
load_lab( )
5
On your own
12. Do healthier snacks cost more or less than less healthy snacks?
a) What is the code that you used to create a plot?histogram(~cost|healthy_level, data = food)
c) Answer the question. Food that is more healthy tended to cost more than the food that was
less healthy.
13. What other variables seem to be related to the cost of a snack? Indicate the code and the
plot
you used to answer the questions. Describe their relationships.