knitr::opts_chunk$set(
  echo = F, message = F, warning = F,
  fig.path = "man/figures/",
  collapse = T,
  comment = "#>"
  )

library(jsmp)

jsmp


This package does variety of things I find useful when working with R Tidyverse:


Installation

devtools::install_github("ymer/jsmp")


Custom ggplot theme

mtcars |> ggplot(aes(x = mpg, y = disp)) +
   geom_point()


ggplot functions


General functions

mtcars |> 
   group_by(am, gear) |> 
   dplyr::summarise(mean_mpg = mean(mpg)) |> 
   group_vars()
mtcars |> 
   group_by(am, gear) |> 
   summarise(mean_mpg = mean(mpg)) |> 
   group_vars()




ToothGrowth |> 
   group_by(supp) |> 
   ci_means(len) |> 
   ggplot(aes(y = supp, x = mean)) +
   geom_crossbar(aes(xmin = ci.lower, xmax = ci.upper), width = 0.3, size = 0.7, color = c1)


mtcars |> 
   mutate(cyl = as.character(cyl)) |> 
   count(cyl) |> 
   mutate(total = sum(n)) |> 
   ci_proportions() |> 
   ggplot(aes(x = cyl, y = proportion)) +
   geom_col(position = position_dodge()) +
   gg_y_percent_zero() +
   gg_legend_notitle() +
   labs(y = "", x = "") +
   geom_errorbar(aes(ymin = ci.lower, ymax = ci.upper),
                  width=.2, position=position_dodge(.9))


only_high_values <- T
mtcars |> do_if(only_high_values, ~ . |> filter(disp > 180)) |> 
   summarise(mean(disp))
only_high_values <- F
mtcars |> do_if(only_high_values, ~ . |> filter(disp > 180)) |> 
   summarise(mean(disp))
high_or_low <- "low"
mtcars |> do_if(high_or_low == "high", 
                 ~ .x |> filter(disp >= 180), 
                 ~ .x |> filter(disp < 180)) |> 
   summarise(mean(disp))


mtcars |> filter_duplicates(wt)


iris |> fix_names() |> 
   head()


df1 <- tribble(
   ~id, ~v1,
   1, 2,
   2, 2,
   3, 10)

df2 <- tribble(
   ~id, ~v2,
   1, 2,
   3, 4)

left_join(df1, df2)
left_join0(df1, df2)


percent(0.173234235)


df <- mtcars |> head()
for (row in rows(df)){
   print(row$mpg)
}


ToothGrowth |>
   filter(len > 20) |> 
   tab(supp)


mtcars |> 
   rownames_to_column() |> 
   transpose()


Imported packages



ymer/jsmp documentation built on Jan. 2, 2022, 6:17 p.m.