LoslegenKostenlos loslegen

Default trend lines

ggplot2 gives us powerful tools to visualize our data and "see" what is going on. However, sometimes we need to wrangle our data to give us what we need. During this exercise, you will look and see if the length of commutes changes the chance somebody rides the bus. You will do this by changing the points to be non-overlapping (or jittered) using geom_jitter() and adding smoothed trend line with geom_smooth().

Diese Übung ist Teil des Kurses

Generalized Linear Models in R

Kurs anzeigen

Anleitung zur Übung

  • Using the data.frame bus, plot MilesOneWay on the x-axis and Bus2 on the y-axis.
  • Jitter the width of the data by 0 and the height by 0.05.
  • Label the axes on the plot. Use "Probability of riding the bus" on the y-axis and "One-way commute trip (in miles)" on the x-axis.
  • Save this plot as gg_jitter then add geom_smooth()

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Create a jittered plot of MilesOneWay vs Bus2 using the bus dataset
gg_jitter <- ggplot(data = ___, aes(x = ___, y = ___)) + 
	geom_jitter(width = ___, height = ___) +
	ylab(___) +
	xlab(___)

# Add a geom_smooth() to your plot
gg_jitter + ___
Code bearbeiten und ausführen