For a data set of your choosing, make a faceted plot using the trelliscopejs package. You may make any type of plot; scatter plot, histogram, etc. but, as mentioned in the discussion below, you must explain why you chose this plot and what you are investigating about the variable you are graphing.
The trelliscope plot must include one cognostic measure of your own. Include a description of what it is and what information this measure gives.
Description 2-3 paragraphs.
Describe the data set. Explain the variable you are graphing in your plots and the reason you are investigating with it. Discuss the reason/motivation you chose the variable to facet on, and what insight or trend you are attempting to investigate. Discuss any challenges you had in making the graphs and how you dealt with these challenges. Name at least one cognostic measure (this can include the cognostic you created or be different) the reader could investigate, and explain any insight they might gain from it.
knit the file to an html document
publish this to an RPubs page.
grading: trelliscope plot[25 points], discussion[25 points]
Note: you can add a url directly to the text and it will be active in the html (and word document if you knit to that)
Example: https://www.google.com
If you want to be fancy and make your url active text, you can do this
The data utilized is the loans data per country available from https://www.kaggle.com/datasets/kinantytasya/quiz-sas-to-python?rvi=1. The features available in the data give attributes of the loans requested and approved by different countries around the world. For the case of the task, a sample of 3000 loans from the data were used and the countries with the top 10 most loans selected for further analysis and plotting using the trelliscopejs package.
The faceted scatterplots give the lender count against the loan amount by country for the top 10 countries that seek loans in terms of frequency. The interest in the relationship between the loan amount and the lender count is the determination of how the number of lenders willing to provide credit to a country affects the loan amount that the country requests for.
The production of the graphs was challenging in the how to produce the cognostic measure and include in the plots. This was a departure from what is possible through groupby() and mutate() functions with the map_cog() function allowing for a combination of what the groupby() and mutate() functions normally offer. The cognostic measure selected was the sector type measure for the most frequent sector type for which the loans are requested in each country; this gives insight on the development preferences for the countries for utilization of loans.
Link for RPubs available from https://rpubs.com/Sayannolla93/1170559
# Loans Data
library(tidyverse)
## ── 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.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── 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
loan_kiva <- read_csv("loan_kiva.csv")
## Rows: 323279 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): activity, sector, country, region, currency, repayment_interval
## dbl (6): id, funded_amount, loan_amount, partner_id, term_in_months, lender...
## dttm (2): posted_time, funded_time
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Taking a sample of the first 3000 observations
loan_kiva <- loan_kiva[1:3000, ]
# Taking countries with top 10 highest frequency in the data
loan_kiva_t10 <- loan_kiva %>%
add_count(country) %>%
filter(n %in% tail(sort(unique(n)),10)) %>%
arrange(desc(n))
library(trelliscopejs)
loan_kiva_t10 %>%
nest(data = !one_of(c("country"))) %>%
mutate(
cogs = map_cog(data, ~ tibble(
most_common_sector = cog(tail(names(table(.$sector)), 1), desc = "Most common sector type for loan request")
)),
panel = map_plot(data, ~
qplot(lender_count, loan_amount, data = .) + xlab("lender_count") + ylab("loan_amount") +
xlim(0, 155) + ylim(70, 6700) + theme_bw())) %>%
trelliscope(name = "Lender Count against Loan Amount", nrow = 2, ncol = 5, width = 500, path = "rmarkdown_files",
self_contained = TRUE)
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `panel = map_plot(...)`.
## Caused by warning:
## ! `qplot()` was deprecated in ggplot2 3.4.0.