── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(highcharter)
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Attaching package: 'highcharter'
The following object is masked from 'package:dslabs':
stars
ggplot(gapminder_filtered, aes(x = gdp, y = life_expectancy, color = continent)) +geom_point(size =3, alpha =0.5) +# Scatterplot pointsscale_x_log10() +# Transform GDP to a log scale for better visualizationlabs(title ="GDP vs. Life Expectancy (2005)", x ="GDP per Capita (log scale)", y ="Life Expectancy (years)", color ="Continent" ) +theme_minimal() +# Change the default themetheme(plot.title =element_text(size =14, face ="bold"),axis.text =element_text(size =10),legend.position ="bottom" )
Warning: Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
highchart() %>%hc_chart(type ="scatter") %>%hc_add_series(data = gapminder_filtered,type ="scatter",name ="Country",mapping =hcaes(x = gdp, y = life_expectancy, group = continent),marker =list(radius =5) ) %>%hc_title(text ="GDP vs. Life Expectancy (2005)") %>%hc_xAxis(title =list(text ="GDP per Capita (log scale)"), type ="logarithmic") %>%hc_yAxis(title =list(text ="Life Expectancy (years)")) %>%hc_tooltip(pointFormat ="Country: {point.country}<br>GDP: {point.x}<br>Life Expectancy: {point.y}")
I first began this assignment by using tidyverse to create a scatter plot that showed the association between GDP per capita and life expectancy for various nations in 2005. To make the data easier to understand, I plotted GDP on a logarithmic scale. I also used different colors for each continent to draw attention to regional variations. Although it was evident from the static graph that nations with higher GDP per capita typically have longer life expectancies, I found it challenging to examine individual data points without overcrowding the graph with labels. Then I came upon highcharter, which fundamentally altered my perspective on data visualization! I created an interactive scatter plot using HighCharter that allows visitors to hover over individual points to view information like as life expectancy, GDP, and the name of the nation. This greatly simplified the process of analyzing particular nations without superfluous text being added to the graph. With life expectancy on the y-axis and GDP per capita on the x-axis (log scale), the arrangement is comparable to my first graph; however, the main distinction is how much more interesting and user-friendly this version is.The fact that highcharter adapts to user inputs automatically, making it far more dynamic than tidyverse, is among my favorite features. To make it more aesthetically pleasing, I also included a legend and changed the colors for each continent. Compared to the static graph, it felt lot more intuitive and enjoyable to study because I could see the data move as I hovered over points. I had never used HighCharter before, but i watched videos and did research and I was pleasantly surprised by how simple it was to make my graph interactive while maintaining the clarity of all the important details. I can definitely see me utilizing highcharter for projects in the future now that I am aware of it!