MulaiMulai sekarang secara gratis

Region premiums

In this exercise, your objective is to plot histograms that compare the yearly insurance premiums of policyholders across different regions. To achieve this, you will define a plotting chain that adjusts the units of the insurance charges from dollars to thousands of dollars, enhancing the visualization. You will plot the histograms on a two-by-two grid.

The DataFrames, StatsPlots and Chain packages have been imported, and the insurance DataFrame has been loaded.

Latihan ini adalah bagian dari kursus

Introduction to Data Visualization with Julia

Lihat Kursus

Petunjuk latihan

  • Apply the transform() function to divide each element of the :Charges column by 1000 and assign the resulting values back to the same column.
  • Set the layout argument to generate a two-by-two grid of histograms.
  • Customize the axis labels by setting the x-axis label of the bottom two histograms to "Premium (kUSD)", and set the y-axis label of the first and third histograms to "Frequency".

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

colors = [:slategray1 :springgreen4 :deeppink :darkviolet]

@chain insurance begin
	# Change charge units
    transform(:____
    	=> ByRow(x -> ____) => :____)
	# Create histograms
    @df histogram(:Charges, group=:Region,
    	layout=____,
        color=colors,
        # Set axis labels
        xlabel=____,
        ylabel=____)
end
ylims!(0, 120)
Edit dan Jalankan Kode