Upload app.py
Browse files13 unmodified lines14151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727313 unmodified lines# First Visualizationst.header("Total Recorded Bigfoot Sightings by State")state_counts = df["state"].value_counts().reset_index()state_counts.columns = ["state", "count"]# Base bar chart for statesstate_bar = alt.Chart(state_counts).mark_bar().encode(y=alt.Y('state:N', sort='-x', title="State"),x=alt.X('count:Q', title="Number of Sightings"),tooltip=["state", "count"],color=alt.condition(alt.selection_point(on='click', empty='none', fields=['state']),alt.value('orange'), # clicked coloralt.value('steelblue') # default color)).add_params(alt.selection_point(fields=['state'], name="Select", empty="none")).properties(width=600, height=800)st.altair_chart(state_bar)# Create the selectionselection = alt.selection_point(fields=['state'], empty='none')# Filter dataset based on clicked stateselected_state = st.session_state.get('selected_state')# Use the clickstate_click = alt.selection_point(fields=['state'], empty='none', name="Select")# Reactive chart for season breakdown if a state is clickedseason_chart = (alt.Chart(df).transform_filter(state_click).mark_bar().encode(x=alt.X('season:N', title="Season"),y=alt.Y('count():Q', title="Number of Sightings"),color='season:N').properties(width=400, height=300))combined = alt.vconcat(state_bar.add_params(state_click),season_chart)st.altair_chart(combined)# Analysis for First Visualizationst.write("""This first visualization presents a horizontal bar chart showing the numberof reported Bigfoot sightings across different U.S. states. The goal is tohighlight the states where these reports are most prevalent. To create thischart, I grouped the dataset by the state column and counted the number ofreports associated with each state. Any states with no sightings were droppedfrom the data. I used a bar encoding for the count, sorted in descending order,with the state names displayed along the y-axis. This simple visual allows forquick comparison of sighting frequency by location.""")13 unmodified lines141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118213 unmodified lines# First Visualizationst.header("Total Recorded Bigfoot Sightings by State")# Create the selectionstate_click = alt.selection_point(fields=['state'], name="state_select", empty='none')# Sightings by state bar chartstate_counts = df['state'].value_counts().reset_index()state_counts.columns = ['state', 'count']state_bar = alt.Chart(state_counts).mark_bar().encode(y=alt.Y('state:N', sort='-x', title="State"),x=alt.X('count:Q', title="Number of Sightings"),tooltip=["state", "count"],color=alt.condition(state_click,alt.value('orange'),alt.value('steelblue'))).add_params(state_click).properties(width=600, height=800)season_colors = alt.Color('season:N',title='Season',scale=alt.Scale(domain=['Spring', 'Summer', 'Fall', 'Winter','Unknown'],range=['#66c2a5', '#fc8d62', '#8c510a', '#3288bd','#d62728'] # green, orange, brown, blue, red),legend=None)# Season breakdown chartseason_chart = (alt.Chart(df).transform_filter(state_click).mark_bar().encode(x=alt.X("season:N", title="Season"),y=alt.Y("count():Q", title="Number of Sightings"),color=season_colors).properties(width=400, height=300))# Combine and rendercombined_chart = alt.vconcat(state_bar,season_chart).configure_view(stroke=None).properties(padding={"bottom": 75})st.altair_chart(combined_chart)# Analysis for First Visualizationst.write(""" "This first visualization presents a horizontal bar chart showing the numberof reported Bigfoot sightings across different U.S. states. The goal is tohighlight the states where these reports are most prevalent. To create thischart, I grouped the dataset by the state column and counted the number ofreports associated with each state. Any states with no sightings were droppedfrom the data. I used a bar encoding for the count, sorted in descending order,with the state names displayed along the y-axis."""")st.write('''This visualization is similar to the first one I had in my HW5 submission,but differs slightly in that I made it interactive for this assignment. I addedthe option to select a bar/state from the graph to then display the sightingsby season for that state in another bar chart visualization below. I also addedan 'Unknown' column to the seasonal sightings bar chart, as there are somesightings that do not have a recorded date to then map to a season. If I hadmore time, adding the option to compare states' results with a multi-selectfilter could be insightful.''')# Second Visualizationst.header("Total Recorded Bigfoot Sightings by Moon Phase")# Drop missing moon_phase and seasondf = df.dropna(subset=["moon_phase", "season"]).copy()# Convert moon_phase to labelsdef moon_phase_label(val):if val < 0.125:return "New Moon"elif val < 0.25:return "Waxing Crescent"elif val < 0.375:return "First Quarter"elif val < 0.5:return "Waxing Gibbous"elif val < 0.625:return "Full Moon"elif val < 0.75:return "Waning Gibbous"elif val < 0.875:return "Last Quarter"else:return "Waning Crescent"df.loc[:, "moon_phase_label"] = df["moon_phase"].apply(moon_phase_label)# Moon phase color palettemoon_colors = {"New Moon": "#222222","Waxing Crescent": "#444444","First Quarter": "#666666","Waxing Gibbous": "#888888","Full Moon": "#ffffcc","Waning Gibbous": "#999999","Last Quarter": "#666666","Waning Crescent": "#444444"}# Dropdown for season filterseasons = sorted(df["season"].dropna().unique())selected_season = st.selectbox("Season", seasons)# Filtered datafiltered_df = df[df["season"] == selected_season]# Radial moon chartmoon_chart = alt.Chart(filtered_df).mark_arc(innerRadius=50).encode(theta=alt.Theta("moon_phase_label:N", sort=list(moon_colors.keys())),radius=alt.Radius("count()", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)),color=alt.Color("moon_phase_label:N",scale=alt.Scale(domain=list(moon_colors.keys()), range=list(moon_colors.values())),title="Moon Phase"),tooltip=["moon_phase_label:N", "count()"]).properties(width=500,height=500,padding={"top": 75, "bottom": 75},)st.altair_chart(moon_chart)# Analysis for Second Visualizationst.write(""" This second visualization presents an arc chart displaying the numberof reported Bigfoot sightings according to the moon phase at the time of thesighting. The goal is to explore whether certain phases of the moon are associatedwith a higher frequency of reports. To create this chart, the dataset was filteredto remove missing moon phase data, and the moon phase values were grouped intoeight labeled categories (e.g., New Moon, Full Moon). I used a polar coordinatesystem to arrange the moon phases in a circular format, reflecting the naturallunar cycle, and applied a distinct color to each phase for easier interpretation.A dropdown selection also allows users to explore patterns by season. I was fairlyunfamiliar with arc charts prior to this, but was researching differentvisualizations I could add to this submission, and chose this one for moonphases. I referenced the [Altair documentation](https://altair-viz.github.io/user_guide/marks/arc.html)to complete this.""")st.write('''This visualization is new between my HW5 assignment and this assignment. If Ihad more time, I would improve this visualization by allowing a viewer to selectmultiple seasons at once to compare how moon phase sightings vary across differenttimes of the year. I could also refine the moon phase labels by using more precise phasesinstead of broader ones (like 'Early Waxing Crescent'), and adjust the color schemeto better represent moonlight intensity across phases.''')st.header("Overall Analysis")st.write(''' "Bigfoot is most commonly associated with being a creature of the Pacific Northwest,which includes Washington and Oregon. It makes sense then that these two states are in thetop 5 of states with Bigfoot sightings and have a large amount of sightings visually groupedtogether on the two maps. There does not seem to be too much of a correlation betweensightings and seasons, at least based on visual cues given from the" charts above. Resultsvary as well with the seasonal moon phase data, with there not appearing to be a strongcorrelation between moon phases and reported Bigfoot sightings.''')
app.py+140-31