LoslegenKostenlos loslegen

Smokers by age

In this exercise, your task is to compare the demographics of policyholders based on their age and smoker status. To achieve this, you will generate two histograms representing the ages of smokers and non-smokers. The histograms will be displayed one on top of the other by manipulating the figure layout.

The DataFrames and StatsPlots packages have been imported, and the insurance DataFrame, containing the relevant data, has been loaded for your convenience.

Diese Übung ist Teil des Kurses

Introduction to Data Visualization with Julia

Kurs anzeigen

Anleitung zur Übung

  • Utilize the DataFrame recipe to create histograms of the :Age column, using data from the insurance DataFrame and grouping them by the :Smoker status.
  • Set the layout argument to display both plots, one above the other.
  • Assign the label "Age" to the x-axis of the bottom histogram only.

Interaktive Übung

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

# Create histograms
____ ____ histogram(
	:____,
    group=:____,
    color=[:mediumorchid :seagreen],
    legend_title="Smoker",
    legend_position=:outertopright,
    # Set layout
    layout=____,
    # Label x-axes
    xlabel=[____ ____]
)
ylims!(0, 120)
ylabel!("Frequency")
Code bearbeiten und ausführen