UBC-MDS / DSCI_522_group_31

Other
1 stars 6 forks source link

Maybe put your figure into more columns instead of one single column #54

Closed ericlee0920 closed 3 years ago

tdkhanhvu commented 3 years ago

We can split the numeric columns into 2 groups and draw 2 charts and stack them vertically. The reason is that currently I am using melt to transform data into density plot, and it does not support multiple columns.

You can extract the charting code into a separate function to reduce DRY

numeric_features = ["Administrative", "Administrative_Duration",
                    "Informational", "Informational_Duration",
                    "ProductRelated", "ProductRelated_Duration",
                    "BounceRates", "ExitRates", "PageValues", "SpecialDay"]

num1 = numeric_features[:5]
num2 = numeric_features[5:]

chart1 = (alt.Chart(df, title="Density plot for numeric features")
         .transform_fold(
             num1,
             as_ = ["Features", "value"])
         .transform_density(
             density="value",
             bandwidth=0.3,
             groupby=["Features", "Revenue"],
             extent= [0, 8])
         .mark_area(opacity=0.3)
         .encode(
             x=alt.X("value:Q", title="Value", axis=None),
             y=alt.Y("density:Q", title="", axis=None),
             row=alt.Row("Features:N"),
             color="Revenue")
         .properties(width=250, height=100))

chart2 = (alt.Chart(df, title="Density plot for numeric features")
         .transform_fold(
             num1,
             as_ = ["Features", "value"])
         .transform_density(
             density="value",
             bandwidth=0.3,
             groupby=["Features", "Revenue"],
             extent= [0, 8])
         .mark_area(opacity=0.3)
         .encode(
             x=alt.X("value:Q", title="Value", axis=None),
             y=alt.Y("density:Q", title="", axis=None),
             row=alt.Row("Features:N"),
             color="Revenue")
         .properties(width=250, height=100))

chart1 | chart2
yaz-saleh commented 3 years ago

Group discussion notes: