File size: 3,823 Bytes
3ddfd7a
9de66d5
3ddfd7a
 
9de66d5
91a71ee
9de66d5
91a71ee
 
 
 
9de66d5
64d50ce
9de66d5
f501747
9de66d5
 
 
3ddfd7a
9de66d5
3ddfd7a
9de66d5
91a71ee
 
3ddfd7a
91a71ee
 
 
 
0e82be3
91a71ee
 
58baab8
9de66d5
 
 
91a71ee
58baab8
0e82be3
91a71ee
3ddfd7a
9de66d5
91a71ee
 
9de66d5
91a71ee
 
 
9de66d5
313238f
91a71ee
9de66d5
51d9500
91a71ee
58baab8
2e641aa
 
 
 
 
91a71ee
 
0e82be3
91a71ee
 
58baab8
9de66d5
 
 
91a71ee
58baab8
91a71ee
 
51d9500
9de66d5
91a71ee
 
9de66d5
91a71ee
 
 
9de66d5
313238f
91a71ee
9de66d5
51d9500
9de66d5
 
 
 
d1af9ee
9de66d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import streamlit as st
import pandas as pd
import altair as alt

# Title and Introduction
st.title("Building Inventory Analysis")
st.markdown("""
This application provides insights into the building inventory dataset through two visualizations:
1. **Building Count by County**: Displays the number of buildings in each county.
2. **Year-wise Construction of Buildings**: Shows the count of buildings constructed each year.
Each visualization is accompanied by a brief explanation, including design choices and potential improvements.
""")

# Load Dataset
@st.cache_data
def load_data():
    url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
    return pd.read_csv(url)

data = load_data()

# Data Preprocessing
# Ensure 'Year Constructed' is numeric
data['Year Constructed'] = pd.to_numeric(data['Year Constructed'], errors='coerce')

# Visualization 1: Building Count by County
st.header("1. Building Count by County")
county_count = data['County'].value_counts().reset_index()
county_count.columns = ['County', 'Building Count']

county_chart = alt.Chart(county_count).mark_bar(color='teal').encode(
    alt.X('Building Count:Q', title='Number of Buildings'),
    alt.Y('County:N', sort='-x', title='County')
).properties(
    width=700,
    height=400,
    title='Number of Buildings per County'
)

st.altair_chart(county_chart, use_container_width=True)

st.markdown("""
**Explanation**:
This bar chart illustrates the number of buildings in each county, highlighting areas with higher concentrations of government buildings.
- **Design Choices**:
  - A horizontal bar chart is used to accommodate long county names and facilitate easy comparison.
  - Counties are sorted in descending order based on building count to emphasize those with the most buildings.
  - The teal color provides a calm and professional appearance.
- **Potential Improvements**:
  - Create grouped bar charts to compare building counts by county across different years.
  - Add a map visualization to provide spatial context to the data.
""")

# Visualization 2: Year-wise Construction of Buildings
st.header("2. Year-wise Construction of Buildings")
# Filter out rows where 'Year Constructed' is 0 or NaN
data_filtered = data[(data['Year Constructed'] > 0) & (~data['Year Constructed'].isna())]

# Group by 'Year Constructed' and count the number of buildings
yearly_construction = data_filtered['Year Constructed'].value_counts().reset_index()
yearly_construction.columns = ['Year Constructed', 'Building Count']
yearly_construction = yearly_construction.sort_values('Year Constructed')

year_chart = alt.Chart(yearly_construction).mark_line(point=True, color='orange').encode(
    alt.X('Year Constructed:Q', title='Year Constructed'),
    alt.Y('Building Count:Q', title='Number of Buildings')
).properties(
    width=700,
    height=400,
    title='Number of Buildings Constructed Over Time'
)

st.altair_chart(year_chart, use_container_width=True)

st.markdown("""
**Explanation**:
This line chart displays the number of buildings constructed each year, revealing trends and periods of increased construction activity.
- **Design Choices**:
  - A line chart effectively shows changes over time and highlights trends.
  - Data points are marked to emphasize individual years.
  - The orange color draws attention to the trend line.
- **Potential Improvements**:
  - Overlay a trendline to highlight long-term construction patterns while reducing the effect of year-to-year fluctuations.
  - Allow users to filter the data by building type or agency to explore specific trends.
""")

# Footer
st.markdown("""
---
**Data Source**: [Building Inventory Dataset](https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv)  
**Author**: Maanas Agrawal
""")