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 used in the analysis in this task is the New York crimes data containing information on the crimes committed in the state of New York from the year 1990 to the year 2018. The observations in this data were by the county and police agency to which the crime was reported. Using this data sourced from https://www.kaggle.com/datasets/new-york-state/new-york-state-index-crimes, the plotting in this task was developed for the scatterplot of the motor vehicle theft and the murder incidents in the state of New York. The motor vehicle theft variable is a variable with information on the number of vehicle theft crimes that have been reported to the various agencies in the various counties in the state of New York. The murder variable provides information on the number of murder crimes reported in the various agencies in the various counties in the state of New York. The investigation of the association between the two variables will provide information on whether the motor vehicles crimes are related to murder crimes in the state.
# Data and Data Preparation
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
NY_Crimes <- read_csv("index-crimes-by-county-and-agency-beginning-1990.csv")
## Rows: 19956 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): County, Agency, Region
## dbl (12): Year, Months Reported, Index Total, Violent Total, Murder, Rape, R...
##
## ℹ 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.
NY_Crimes <- na.omit(NY_Crimes)
Faceting using the trelliscope () function is a bit complicated but similar to the case of adding the facet_trelliscope () to the ggplot plots. This was challenging since the facets in trelliscope () is not called using a logical parameter, but instead requires the assigning of facet grid row numbers and column numbers to the nrow and ncol parameters. The year variable was used for faceting with the cognostic measure being the mean violent totals as a possible mediator for contextualizing the relationship between the motor vehicle theft and the murder incidents.
Rpubs: https://rpubs.com/Ghana___/1170601
library(trelliscopejs)
NY_Crimes %>%
nest(data = !one_of(c("Year"))) %>%
mutate(
cogs = map_cog(data, ~ tibble(
mean_violent_total = cog(tail(names(table(.$`Violent Total`)), 1), desc = "Average number of violent crimes")
)),
panel = map_plot(data, ~
qplot(`Motor Vehicle Theft`, Murder, data = .) + xlab("Motor Vehicle Theft") + ylab("Murder") +
xlim(0, 3438) + ylim(0, 149) + theme_bw())) %>%
trelliscope(name = "New York Crimes",
nrow = 3, ncol = 6,
width = 600,
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.