Question 1
data(cars)
median(cars[,1])
## [1] 15
Question 2
library(jsonlite)
fromJSON("https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=99")
## $Response
## [1] "Success"
##
## $Message
## [1] ""
##
## $HasWarning
## [1] FALSE
##
## $Type
## [1] 100
##
## $RateLimit
## named list()
##
## $Data
## $Data$Aggregated
## [1] FALSE
##
## $Data$TimeFrom
## [1] 1764028800
##
## $Data$TimeTo
## [1] 1772582400
##
## $Data$Data
## time high low open volumefrom volumeto close
## 1 1764028800 88494.81 86089.70 88288.33 32065.82 2799155557 87340.82
## 2 1764115200 90634.17 86298.47 87340.82 30484.49 2694221351 90487.28
## 3 1764201600 91934.77 90083.46 90487.28 21381.51 1949917850 91327.26
## 4 1764288000 93116.85 90242.43 91327.26 28364.69 2595318230 90917.53
## 5 1764374400 91201.70 90211.19 90917.53 9605.76 871610719 90842.76
## 6 1764460800 91983.85 90363.83 90842.76 11291.12 1030115400 90381.34
## 7 1764547200 90443.38 83828.42 90381.34 56213.90 4839357128 86302.37
## 8 1764633600 92332.31 86199.69 86302.37 45736.14 4090746747 91315.07
## 9 1764720000 94192.91 91041.20 91315.07 41538.16 3856959978 93464.62
## 10 1764806400 94089.06 90913.17 93464.62 28655.33 2655580450 92106.94
## 11 1764892800 92717.53 88116.59 92106.94 32962.38 2976454083 89352.03
## 12 1764979200 90291.46 88942.96 89352.03 10824.34 969656691 89262.30
## 13 1765065600 91783.95 87756.05 89262.30 19003.30 1705564639 90413.99
## 14 1765152000 92303.63 89623.92 90413.99 29264.71 2657534556 90661.73
## 15 1765238400 94617.10 89530.61 90661.73 33300.59 3069266494 92701.41
## 16 1765324800 94506.56 91582.52 92701.41 31975.44 2959837905 92038.34
## 17 1765411200 93581.10 89281.34 92038.34 34699.18 3150988932 92546.90
## 18 1765497600 92774.35 89499.86 92546.90 23943.19 2181249699 90277.47
## 19 1765584000 90655.09 89789.11 90277.47 4873.94 439868316 90262.18
## 20 1765670400 90495.22 87605.50 90262.18 13925.51 1240055595 88169.62
## 21 1765756800 90044.99 85149.06 88169.62 32063.56 2801710553 86421.58
## 22 1765843200 88144.98 85264.64 86421.58 29881.81 2601098657 87851.74
## 23 1765929600 90343.35 85280.69 87851.74 36654.93 3196552926 86223.21
## 24 1766016000 89450.72 84424.20 86223.21 37000.62 3212930908 85478.70
## 25 1766102400 89360.77 85085.96 85478.70 30053.32 2631213615 88107.20
## 26 1766188800 88542.21 87793.71 88107.20 5509.23 485865199 88340.83
## 27 1766275200 89047.71 87586.96 88340.83 9049.14 798755210 88647.80
## 28 1766361600 90551.12 87881.68 88647.80 29006.12 2587981701 88566.92
## 29 1766448000 88897.58 86559.41 88566.92 23920.90 2097762546 87440.81
## 30 1766534400 88003.03 86365.36 87440.81 16558.92 1443982911 87620.12
## 31 1766620800 88545.97 86913.66 87620.12 8950.93 785512556 87183.32
## 32 1766707200 89503.42 86589.77 87183.32 24423.76 2146285656 87315.10
## 33 1766793600 87925.14 87154.06 87315.10 4960.63 433943569 87823.31
## 34 1766880000 88018.43 87381.32 87823.31 5733.05 502876456 87886.81
## 35 1766966400 90327.16 86704.68 87886.81 30609.16 2698231724 87133.26
## 36 1767052800 89341.34 86732.68 87133.26 22736.07 2002631036 88410.54
## 37 1767139200 89105.68 87109.45 88410.54 18255.84 1607399099 87519.13
## 38 1767225600 88806.59 87400.21 87519.13 9510.96 835819449 88742.68
## 39 1767312000 90940.54 88289.33 88742.68 32178.91 2884180580 89959.25
## 40 1767398400 90692.56 89288.10 89959.25 8300.07 747315428 90598.87
## 41 1767484800 91750.60 90598.62 90598.87 10582.97 965791645 91499.58
## 42 1767571200 94804.38 91483.13 91499.58 32652.53 3048567459 93871.45
## 43 1767657600 94428.70 91210.45 93871.45 29297.33 2727558377 93720.48
## 44 1767744000 93720.65 90363.64 93720.48 26753.28 2453135156 91287.12
## 45 1767830400 91578.27 89212.31 91287.12 29489.79 2669597854 91032.92
## 46 1767916800 91948.91 89596.59 91032.92 29088.95 2639588034 90524.71
## 47 1768003200 90713.65 90279.20 90524.71 4793.55 433879311 90391.76
## 48 1768089600 91164.56 90122.70 90391.76 7635.61 692346756 90885.04
## 49 1768176000 92416.57 90020.58 90885.04 31732.96 2898331130 91199.65
## 50 1768262400 96126.37 90944.45 91199.65 46070.59 4301006824 95374.03
## 51 1768348800 97943.22 94530.69 95374.03 50778.17 4896225428 96945.09
## 52 1768435200 97178.67 95102.98 96945.09 33226.15 3196525933 95583.86
## 53 1768521600 95835.50 94246.25 95583.86 22063.25 2100277133 95521.19
## 54 1768608000 95607.52 95004.98 95521.19 5648.60 538364409 95117.69
## 55 1768694400 95496.67 93583.30 95117.69 8546.82 810822826 93642.09
## 56 1768780800 93642.84 92102.43 93642.09 20554.89 1906749298 92569.44
## 57 1768867200 92813.52 87793.26 92569.44 37990.43 3430827950 88329.83
## 58 1768953600 90502.34 87190.29 88329.83 47306.93 4213648826 89380.69
## 59 1769040000 90290.41 88441.13 89380.69 23966.16 2143899739 89484.18
## 60 1769126400 91140.22 88466.06 89484.18 25137.21 2254080166 89506.66
## 61 1769212800 89821.98 89047.54 89506.66 5309.41 474658685 89107.75
## 62 1769299200 89203.31 86008.64 89107.75 19788.52 1730278902 86581.03
## 63 1769385600 88787.86 86429.64 86581.03 28600.46 2509845962 88274.70
## 64 1769472000 89447.82 87212.27 88274.70 24324.97 2147188639 89136.28
## 65 1769558400 90481.33 88729.36 89136.28 27525.65 2461353227 89182.72
## 66 1769644800 89229.19 83243.73 89182.72 45122.46 3865349822 84528.58
## 67 1769731200 84612.31 81047.62 84528.58 53884.23 4468762184 84135.11
## 68 1769817600 84152.35 76029.54 84135.11 52359.60 4182557013 78664.02
## 69 1769904000 79363.96 75653.86 78664.02 47181.00 3668393771 76910.99
## 70 1769990400 79328.70 74579.63 76910.99 63702.51 4931866234 78690.46
## 71 1770076800 79141.27 72882.55 78690.46 62810.31 4798731140 75679.06
## 72 1770163200 76891.77 71724.93 75679.06 65420.80 4852815767 73021.96
## 73 1770249600 73193.96 62227.01 73021.96 128064.14 8672008182 62811.67
## 74 1770336000 71703.46 60069.72 62811.67 105746.35 7081161122 70535.76
## 75 1770422400 71647.04 67315.50 70535.76 35663.46 2471348000 69259.24
## 76 1770508800 72226.42 68857.91 69259.24 24372.40 1719521389 70297.07
## 77 1770595200 71391.44 68260.19 70297.07 43610.47 3050117447 70108.93
## 78 1770681600 70486.44 67878.02 70108.93 35555.88 2457073818 68807.07
## 79 1770768000 69253.29 65725.74 68807.07 47410.63 3185414005 67039.77
## 80 1770854400 68380.57 65084.07 67039.77 42922.43 2860084574 66220.82
## 81 1770940800 69434.68 65825.83 66220.82 37610.93 2551829375 68816.44
## 82 1771027200 70524.71 68706.51 68816.44 18574.98 1293190972 69790.74
## 83 1771113600 70948.50 68048.86 69790.74 22109.67 1533047880 68800.76
## 84 1771200000 70094.71 67269.90 68800.76 24726.24 1692393594 68869.47
## 85 1771286400 69214.45 66592.03 68869.47 31820.50 2156085886 67477.52
## 86 1771372800 68444.93 65838.10 67477.52 32280.23 2164847402 66434.20
## 87 1771459200 67299.79 65618.44 66434.20 29384.21 1956480959 66983.75
## 88 1771545600 68297.95 66442.67 66983.75 38044.13 2565992687 67997.02
## 89 1771632000 68686.92 67528.59 67997.02 11686.08 796953224 67965.05
## 90 1771718400 68233.91 67170.64 67965.05 11615.92 786667937 67626.88
## 91 1771804800 67663.82 63879.72 67626.88 42373.83 2766008869 64642.48
## 92 1771891200 64996.35 62551.85 64642.48 45607.54 2906212703 64069.84
## 93 1771977600 70005.48 63922.45 64069.84 55809.16 3753044531 67998.99
## 94 1772064000 68867.59 66508.93 67998.99 44886.39 3038274772 67498.16
## 95 1772150400 68227.68 64948.18 67498.16 41323.20 2743694517 65870.53
## 96 1772236800 67756.22 63030.34 65870.53 39423.24 2566186201 66985.30
## 97 1772323200 68190.48 65043.22 66985.30 31940.58 2126537311 65774.35
## 98 1772409600 70116.05 65261.45 65774.35 52714.29 3577629869 68831.94
## 99 1772496000 69257.29 66148.66 68831.94 47295.99 3209229703 68338.00
## 100 1772582400 74083.89 67407.20 68338.00 51045.35 3642240284 73512.06
## conversionType conversionSymbol
## 1 direct
## 2 direct
## 3 direct
## 4 direct
## 5 direct
## 6 direct
## 7 direct
## 8 direct
## 9 direct
## 10 direct
## 11 direct
## 12 direct
## 13 direct
## 14 direct
## 15 direct
## 16 direct
## 17 direct
## 18 direct
## 19 direct
## 20 direct
## 21 direct
## 22 direct
## 23 direct
## 24 direct
## 25 direct
## 26 direct
## 27 direct
## 28 direct
## 29 direct
## 30 direct
## 31 direct
## 32 direct
## 33 direct
## 34 direct
## 35 direct
## 36 direct
## 37 direct
## 38 direct
## 39 direct
## 40 direct
## 41 direct
## 42 direct
## 43 direct
## 44 direct
## 45 direct
## 46 direct
## 47 direct
## 48 direct
## 49 direct
## 50 direct
## 51 direct
## 52 direct
## 53 direct
## 54 direct
## 55 direct
## 56 direct
## 57 direct
## 58 direct
## 59 direct
## 60 direct
## 61 direct
## 62 direct
## 63 direct
## 64 direct
## 65 direct
## 66 direct
## 67 direct
## 68 direct
## 69 direct
## 70 direct
## 71 direct
## 72 direct
## 73 direct
## 74 direct
## 75 direct
## 76 direct
## 77 direct
## 78 direct
## 79 direct
## 80 direct
## 81 direct
## 82 direct
## 83 direct
## 84 direct
## 85 direct
## 86 direct
## 87 direct
## 88 direct
## 89 direct
## 90 direct
## 91 direct
## 92 direct
## 93 direct
## 94 direct
## 95 direct
## 96 direct
## 97 direct
## 98 direct
## 99 direct
## 100 direct
url <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=99"
btc_json <- fromJSON(url)
btc_data <- btc_json$Data$Data
max_close_price <- max(btc_data$close)
print(max_close_price)
## [1] 96945.09
Question 3
Title: Green Around The Globe
Research Questions
1. Is there a statistically significant correlation between a
country’s GDP per capita and its percentage of total energy derived from
renewable sources?
2. Which regions have shown the highest rate of an increasing GDP
while decreasing carbon intensity?
3. How has the global share of solar and wind energy changed in the
top economies since 2015?
Data Cleaning
clean_energy_data <- raw_world_bank %>%
# Rename columns
rename(
gdp_per_cap = NY.GDP.PCAP.CD,
renew_share = EG.FEC.RNEW.ZS,
region = region
) %>%
# Filter out non-country aggregates
filter(region != "Aggregates") %>%
# Handle missing values
drop_na(gdp_per_cap, renew_share) %>%
# Create a categorical variable for GDP levels
mutate(income_level = case_when(
gdp_per_cap > 40000 ~ "High",
gdp_per_cap > 15000 ~ "Middle",
TRUE ~ "Low"
))
Answer to RQ 1 (Is there a statistically significant correlation
between a country’s GDP per capita and its percentage of total energy
derived from renewable sources?)
cor_val <- cor(clean_energy_data$gdp_per_cap, clean_energy_data$renew_share)
ggplot(clean_energy_data, aes(x = gdp_per_cap, y = renew_share)) +
geom_point(aes(color = region), alpha = 0.5) +
geom_smooth(method = "lm", color = "black", linetype = "dashed") +
labs(title = paste("GDP per Capita vs. Renewable Energy Share (r =", round(cor_val, 2), ")"),
x = "GDP per Capita (USD)",
y = "% Renewable Energy Share") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

We have determined that there is a weak negative correlation between
% of renewable energy share and GDP per capita. This means that
globally, there is not a strong connection between GDP and the
transition to renewal energy.
Answer to RQ 2 (Which regions have shown the highest rate of an
increasing GDP while decreasing carbon intensity?)
# Compare distributions across regions
clean_energy_data %>%
group_by(region) %>%
ggplot(aes(x = reorder(region, renew_share, median), y = renew_share, fill = region)) +
geom_boxplot() +
coord_flip() + # Makes regional names easier to read
labs(title = "Renewable Energy Distribution by Region",
x = "Region",
y = "Percentage of Total Energy from Renewables") +
guides(fill = "none") +
theme_light()

This graph shows that Sub-Saharan Africa is the leader in total
energy use that is sourced from renewable energy. In this data, biofuel
such as wood and charcoal is considered to be renewable energy. This
also considers energy use. In rural regions like the majority of
Sub-Saharan Africa, industrial energy use is low, leading to a high
percentage of energy use coming from biofuels used in cooking or
heating.
Answer to RQ3 (How has the global share of solar and wind energy
changed in the top economies since 2015?)
top_economies <- c("United States", "China", "Germany", "India", "Brazil", "Japan")
# Filter and plot time-series
clean_energy_data %>%
filter(country %in% top_economies) %>%
ggplot(aes(x = year, y = renew_share, color = country)) +
geom_line(size = 1.2) +
geom_point() +
labs(title = "Renewable Energy Trends (2015-2025)",
subtitle = "Selected Top Global Economies",
x = "Year",
y = "Renewable Energy Share (%)",
color = "Country") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

This graph shows a slight climb in each nation from 2015 to 2025,
reflective of the global culture switch towards a movement for renewable
energy to become a primary source.