The following object is masked from 'package:maps':
unemp
library(leaflet)data("storms", package ="dplyr")
janitor::get_dupes
function (dat, ...)
{
expr <- rlang::expr(c(...))
pos <- tidyselect::eval_select(expr, data = dat)
is_grouped <- dplyr::is_grouped_df(dat)
if (is_grouped) {
dat_groups <- dplyr::group_vars(dat)
dat <- dat %>% dplyr::ungroup()
if (getOption("get_dupes.grouped_warning", TRUE) & interactive()) {
message(paste0("Data is grouped by [", paste(dat_groups,
collapse = "|"), "]. Note that get_dupes() is not group aware and does not limit duplicate detection to within-groups, but rather checks over the entire data frame. However grouping structure is preserved.\nThis message is shown once per session and may be disabled by setting options(\"get_dupes.grouped_warning\" = FALSE)."))
options(get_dupes.grouped_warning = FALSE)
}
}
if (rlang::dots_n(...) == 0) {
var_names <- names(dat)
nms <- rlang::syms(var_names)
message("No variable names specified - using all columns.\n")
}
else {
var_names <- names(pos)
nms <- rlang::syms(var_names)
}
dupe_count <- NULL
dupes <- dat %>% dplyr::add_count(!!!nms, name = "dupe_count") %>%
dplyr::filter(dupe_count > 1) %>% dplyr::select(!!!nms,
dupe_count, dplyr::everything()) %>% dplyr::arrange(dplyr::desc(dupe_count),
!!!nms)
if (length(var_names) > 10) {
var_names <- c(var_names[1:9], paste("... and", length(var_names) -
9, "other variables"))
}
if (nrow(dupes) == 0) {
message(paste0("No duplicate combinations found of: ",
paste(var_names, collapse = ", ")))
}
if (is_grouped)
dupes <- dupes %>% dplyr::group_by(!!!rlang::syms(dat_groups))
return(dupes)
}
<bytecode: 0x11e012f98>
<environment: namespace:janitor>
ggplot(data=distinct_storms_year, aes(x= year, y= count)) +geom_col() +labs(title="Counts of Storms by Year",x="Year", y="Frequency") +theme_bw()
Question 4
average_windstorms_byyear <-distinct_storms |>group_by(year) |>summarise(mean_wind =mean(wind, na.rm =TRUE), .groups ="drop") |>ggplot(aes(x = year, y = mean_wind)) +geom_line() +#facet_wrap(~ month, ncol = 4) +labs(x ="Years", y ="Average Wind Speeds", title ="Averaged Wind Speeds (of storm) by Years")average_windstorms_byyear
Question 5
states <-map_data("state")katrina <- storms |>filter(name =="Katrina", year ==2005) |># ^This code here makes it so that we only look at the data from the storm Katrina #which happened in the year 2005arrange(year, month, day, hour) #^This groups all these details ggplot() +geom_polygon(data = states,aes(x = long, y = lat, group = group), #^this places the location on the map (via the x and y)fill ="pink", col ="white") +#^This fills in the color for the state area and outlinegeom_path(data = katrina,aes(x = long, y = lat, col = wind)) +#^This whole part shows the wind speeds as a line on the mapcoord_map() +#^It flattens out the mapscale_color_viridis_c(option ="D")
#^This changes the scale color of the line
Question 6
We did not need to join two datasets before plotting the storm path because everything that we already needed is in the dataset. The dataset had the geographic locations, the wind speeds, and the name of the storm.
Question 7
storm_track <-function(storm_name,storm_year,variable){ states <-map_data("state")katrina <- storms |>filter(name == storm_name, year == storm_year) |>arrange(year, month, day, hour) ggplot() +geom_polygon(data = states,aes(x = long, y = lat, group = group), fill ="pink", col ="white") +geom_path(data = katrina,aes(x = long, y = lat, col = wind)) +coord_map() +scale_color_viridis_c(option ="D") }
Unable to answer because I couldn’t reach the end of Question 8. I keep getting errors about objects that do and don’t exist as an input even though it went clear/all the way when I ran the function by itself.
Question 10
leaflet_stormk_counts <- distinct_storms |>filter(year ==2005,!is.na(long), !is.na(lat)) |>group_by(name)|>summarise(n =n(),lon =mean(long, na.rm =TRUE),lat =mean(lat, na.rm =TRUE),.groups ="drop" )leaflet(leaflet_stormk_counts) |>addTiles() |>addPolylines(lng =~lon, lat =~lat, weight =3, color ="#444444") |>addCircleMarkers(lng =~lon, lat =~lat,radius =~scales::rescale(n, to =c(3, 10)),popup =~paste0(name, ": ", n, " storms") )
Reflection
I found Question 8 to be difficult because I keep running into syntax errors. I understand the logic behind making that function and also on how to use the if/error statements. But, I keep running into errors by the system on how the object does/doesn’t exist and about RHS and such. Also, it would work sometimes and stop working at other times. I can’t figure out what exactly is triggering the error so I commented the whole code out in order for the submission to work. I was able to partially do parts of Question 8, but not all of it.. I also need to tweak my graph in Question 10 because it needs a lot of improvements. Those are the things I need to work more on.