base correlations
This commit is contained in:
53
plots.py
53
plots.py
@@ -1048,6 +1048,59 @@ class QualtricsPlotsMixin:
|
||||
chart = self._save_plot(chart, title)
|
||||
return chart
|
||||
|
||||
def plot_speaking_style_color_correlation(
|
||||
self,
|
||||
data: pl.LazyFrame | pl.DataFrame | None = None,
|
||||
title: str = "Speaking Style and Voice Scale 1-10 Correlations<br>(Average by Color)",
|
||||
width: int | str | None = None,
|
||||
height: int | None = None,
|
||||
) -> alt.Chart:
|
||||
"""Plot high-level correlation showing one bar per speaking style color.
|
||||
|
||||
Original use-case: "I want to create high-level correlation plots between
|
||||
'green, blue, orange, red' speaking styles and the 'voice scale scores'.
|
||||
I want to go to one plot with one bar for each color."
|
||||
|
||||
Args:
|
||||
data: DataFrame with columns [Color, correlation, n_traits] from
|
||||
utils.transform_speaking_style_color_correlation
|
||||
title: Chart title (supports <br> for line breaks)
|
||||
width: Chart width in pixels
|
||||
height: Chart height in pixels
|
||||
|
||||
Returns:
|
||||
Altair chart with one bar per speaking style color
|
||||
"""
|
||||
df = self._ensure_dataframe(data)
|
||||
|
||||
# Conditional color based on sign (matches plot_speaking_style_correlation)
|
||||
chart = alt.Chart(df.to_pandas()).mark_bar().encode(
|
||||
x=alt.X('Color:N',
|
||||
title=None,
|
||||
axis=alt.Axis(labelAngle=0),
|
||||
sort=["Green", "Blue", "Orange", "Red"]),
|
||||
y=alt.Y('correlation:Q',
|
||||
title='Average Correlation',
|
||||
scale=alt.Scale(domain=[-1, 1])),
|
||||
color=alt.condition(
|
||||
alt.datum.correlation >= 0,
|
||||
alt.value('green'),
|
||||
alt.value('red')
|
||||
),
|
||||
tooltip=[
|
||||
alt.Tooltip('Color:N', title='Speaking Style'),
|
||||
alt.Tooltip('correlation:Q', format='.3f', title='Avg Correlation'),
|
||||
alt.Tooltip('n_traits:Q', title='# Traits')
|
||||
]
|
||||
).properties(
|
||||
title=self._process_title(title),
|
||||
width=width or 400,
|
||||
height=height or 350
|
||||
)
|
||||
|
||||
chart = self._save_plot(chart, title)
|
||||
return chart
|
||||
|
||||
def plot_demographic_distribution(
|
||||
self,
|
||||
column: str,
|
||||
|
||||
Reference in New Issue
Block a user