Title: | My Toolbox for Assisting Document Editing and Data Presenting |
---|---|
Description: | The purpose of this package is to share a collection of functions the author wrote during weekends for managing kitchen and garden tasks, e.g. making plant growth charts or Thanksgiving kitchen schedule charts, etc. Functions might include but not limited to: (1) aiding summarizing time related data; (2) generating axis transformation from data; and (3) aiding Markdown (with html output) and Shiny file editing. |
Authors: | Y Hsu [aut, cre] |
Maintainer: | Y Hsu <[email protected]> |
License: | AGPL (>= 3) |
Version: | 0.1.8 |
Built: | 2024-11-18 05:09:39 UTC |
Source: | https://github.com/yh202109/mtb |
add_colored_box
returns a box component generated by htmltools
with specified color and styles.
add_colored_box( type = "blue-default", label = "", info = "place details here using info option", bgcolor = NULL, width = 0.5, halign = "c", top = FALSE )
add_colored_box( type = "blue-default", label = "", info = "place details here using info option", bgcolor = NULL, width = 0.5, halign = "c", top = FALSE )
type |
One of:
|
label |
One of:
|
info |
A string including the main message of the box |
bgcolor |
NA or a length 3 vector with integer elements between 0 to 255 |
width |
NA or a number between 0.25 to 0.95 |
halign |
One of:
|
top |
One of:
|
add_colored_box( type='blue-default', info='the document include information regarding...')
add_colored_box( type='blue-default', info='the document include information regarding...')
add_colored_str
returns a string component generated by htmltools
with specified color and styles.
add_colored_str( text = "", color = c(51, 122, 183), alpha = 255, bgcolor = NULL, bgalpha = 51, fontsize = 1, bold = FALSE, it = FALSE )
add_colored_str( text = "", color = c(51, 122, 183), alpha = 255, bgcolor = NULL, bgalpha = 51, fontsize = 1, bold = FALSE, it = FALSE )
text |
A string. default="". |
color |
One of
|
alpha |
An integer between 1 and 255 for text alpha. default=255. |
bgcolor |
One of
|
bgalpha |
An integer between 1 and 255 for background alpha. default=51. |
fontsize |
A real number between 0.5 and 5.0 for font size. default=1. |
bold |
A logical value for bold fonts. default= |
it |
A Boolean value for italic fonts. default= |
a formatted string
add_colored_str("warning: read this message carefully.", color = c(255, 0, 0))
add_colored_str("warning: read this message carefully.", color = c(255, 0, 0))
bill_cross_check
returns a merged data.table showing
information regarding ids and repeated columns.
bill_cross_check(dt1 = NULL, dt2 = NULL, id = NULL, chk = NULL)
bill_cross_check(dt1 = NULL, dt2 = NULL, id = NULL, chk = NULL)
dt1 |
A table. |
dt2 |
A table. |
id |
A column name or a vector of column names |
chk |
A column name |
a data.table
bill_cross_check(data.frame(col1=c(1,2,3,3), col2=c('a','b','c','c'), col3=c('-','=','+','-')),data.frame(col1=c(1,2,3), col2=c('a','b','c'), col3=c('-','=','+')), id=c('col1','col2'), chk='col3')
bill_cross_check(data.frame(col1=c(1,2,3,3), col2=c('a','b','c','c'), col3=c('-','=','+','-')),data.frame(col1=c(1,2,3), col2=c('a','b','c'), col3=c('-','=','+')), id=c('col1','col2'), chk='col3')
bill_cross_count
returns a data.table showing how many times each
items being listed on individual bills.
bill_cross_count( ldt = list(), id = NULL, gp = NULL, type = "count", condstr = "" )
bill_cross_count( ldt = list(), id = NULL, gp = NULL, type = "count", condstr = "" )
ldt |
A list of grocery tables in data.frame format. |
id |
A column name |
gp |
A column name or a vector of column names |
type |
A string in one of the following:
|
condstr |
A string for conditional counting |
a data.table
bill_cross_count(list(cbind(col1=c('a','b','c'),col2=c(1,2,3)), cbind(col1=c('d','c','d'),col2=c(4,5,6))), id='col1')
bill_cross_count(list(cbind(col1=c('a','b','c'),col2=c(1,2,3)), cbind(col1=c('d','c','d'),col2=c(4,5,6))), id='col1')
Create a list of colors for a data vector by a list major colors.
color_set_palette( vect = c(), vectn = c(), cols = c("blue", "cyan", "darkorange"), black = "", gray9 = "" )
color_set_palette( vect = c(), vectn = c(), cols = c("blue", "cyan", "darkorange"), black = "", gray9 = "" )
vect |
A vector for groups. |
vectn |
An integer vector with length 0 or with the same length of |
cols |
One of
|
black |
A level in |
gray9 |
A level in |
a named vector
color_set_palette( c('apple', 'orange', 'lime', 'apple'), c(2,1,3,2), 'red', 'blue')
color_set_palette( c('apple', 'orange', 'lime', 'apple'), c(2,1,3,2), 'red', 'blue')
Create a figure using the assigned color vector
color_test_palette(colvect = c(), type = "line")
color_test_palette(colvect = c(), type = "line")
colvect |
A vector returned by |
type |
One of
|
A plot
color_test_palette( setNames(c(1,2,3,4), c('apple','orange','avocado','lime') ))
color_test_palette( setNames(c(1,2,3,4), c('apple','orange','avocado','lime') ))
Create a plot for events with labels
time_plot_event(dt, xlab = "Time", anchor = TRUE, compact = FALSE)
time_plot_event(dt, xlab = "Time", anchor = TRUE, compact = FALSE)
dt |
a
|
xlab |
A string for the x-axis title |
anchor |
A Boolean value for the vertical lines linking |
compact |
A Boolean value for reducing the vertical spacing when applicable |
a plot
library(ggplot2) dt = data.frame( id=paste('member',c(rep(c(1,2,3),each=3),3),sep=""), idn=c(rep(1,3),rep(-1,3), rep(2,4)), start=1800*c(0,1,2, 0.5, 1.2, 3, 1,2,3,4), end=1800*c(2,NA,3, 2, 6, NA, 2,2.5,3, 3.5), label=c(paste('event-',seq(1,10),sep='')), labelend=c('','','?',')','','','','','>','X'), type=c('b', 'p', 'i','i','p','p','p','b','i','i' ), color=c('stove', 'oven', 'oven','oven','stove','oven','oven','other','stove','oven' ) ) time_plot_event( dt )
library(ggplot2) dt = data.frame( id=paste('member',c(rep(c(1,2,3),each=3),3),sep=""), idn=c(rep(1,3),rep(-1,3), rep(2,4)), start=1800*c(0,1,2, 0.5, 1.2, 3, 1,2,3,4), end=1800*c(2,NA,3, 2, 6, NA, 2,2.5,3, 3.5), label=c(paste('event-',seq(1,10),sep='')), labelend=c('','','?',')','','','','','>','X'), type=c('b', 'p', 'i','i','p','p','p','b','i','i' ), color=c('stove', 'oven', 'oven','oven','stove','oven','oven','other','stove','oven' ) ) time_plot_event( dt )
Create a plot for event periods by ID
time_plot_interval( dt, xlab = "DateTime", ylab = "ID", legend_title = "Group", arrow_wt = 1, arrow_color = "black" )
time_plot_interval( dt, xlab = "DateTime", ylab = "ID", legend_title = "Group", arrow_wt = 1, arrow_color = "black" )
dt |
a
|
xlab |
A string for the label of X-axis |
ylab |
A string for the label of Y-axis |
legend_title |
A string for the title of legend |
arrow_wt |
An integer for the weight of arrow |
arrow_color |
A string for the color of arrow |
a plot
library(ggplot2) dt = data.frame( id=c('ID01','ID12','ID3'), idn=c(1,3,2), start=1800*c(0,1,2), end=1800*c(2,-1,3), label=c('A','B','C') ) time_plot_interval( dt, xlab='Time', ylab='ID', legend_title='Group', arrow_wt=3, arrow_color='gray')
library(ggplot2) dt = data.frame( id=c('ID01','ID12','ID3'), idn=c(1,3,2), start=1800*c(0,1,2), end=1800*c(2,-1,3), label=c('A','B','C') ) time_plot_interval( dt, xlab='Time', ylab='ID', legend_title='Group', arrow_wt=3, arrow_color='gray')
trans_composition()
derives a transformation from a numerical vector with a smaller number (ideally < 30) of distinct values.
The return can be used with function ggplot::scale_x_continuous()
or ggplot::scale_y_continuous()
to create a desired axis.
trans_composition(x = NULL, nb = 30, brk = NA, dab = NA, dgrd = NA, dgrd2 = NA)
trans_composition(x = NULL, nb = 30, brk = NA, dab = NA, dgrd = NA, dgrd2 = NA)
x |
A numerical vector used in a plot as (typically) |
nb |
An integer for the maximum number of breaks. Default=30 |
brk |
One of
|
dab |
One of
|
dgrd |
One of
|
dgrd2 |
One of
|
A transformation function
library(ggplot2) pdt=data.frame(x=rep(c(0.5, 1, 10,11,12, 100, 1000), each=5)) pdt$y=pdt$x+rnorm(length(pdt$x)) t=trans_composition(pdt$x,brk=50, dab=3) ggplot(pdt, aes(x=x, y=y))+geom_point()+scale_x_continuous(trans=t)
library(ggplot2) pdt=data.frame(x=rep(c(0.5, 1, 10,11,12, 100, 1000), each=5)) pdt$y=pdt$x+rnorm(length(pdt$x)) t=trans_composition(pdt$x,brk=50, dab=3) ggplot(pdt, aes(x=x, y=y))+geom_point()+scale_x_continuous(trans=t)
trans_loglinear()
derives a log transformation from a numerical vector with a smaller number (ideally < 30) of distinct values..
The return can be used with function ggplot::scale_x_continuous()
or ggplot::scale_y_continuous()
to create a desired axis.
trans_loglinear(x = NULL, nb = 30, int = NA, scale = NA, mindist = 0.03)
trans_loglinear(x = NULL, nb = 30, int = NA, scale = NA, mindist = 0.03)
x |
A numerical vector used in a plot as (typically) |
nb |
An integer for the maximum number of breaks. Default=30 |
int |
One of
|
scale |
One of
|
mindist |
One of
|
A transformation function
library(ggplot2) pdt=data.frame(x=rep(c(0.5, 1, 10,11,12, 100, 1000), each=5)) pdt$y=pdt$x+rnorm(length(pdt$x)) t=trans_loglinear(pdt$x) ggplot(pdt, aes(x=x, y=y))+geom_point()+scale_x_continuous(trans=t)
library(ggplot2) pdt=data.frame(x=rep(c(0.5, 1, 10,11,12, 100, 1000), each=5)) pdt$y=pdt$x+rnorm(length(pdt$x)) t=trans_loglinear(pdt$x) ggplot(pdt, aes(x=x, y=y))+geom_point()+scale_x_continuous(trans=t)