Title: | Political Science Academic Research Gears |
---|---|
Description: | Using these tools to simplify the research process of political science and other social sciences. The current version can create folder system for academic project in political science, calculate psychological trait scores, visualize experimental and spatial data, and set up color-blind palette, functions used in academic research of political psychology or political science in general. |
Authors: | Yue Hu [aut, cre], Wen Deng [ctb] |
Maintainer: | Yue Hu <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-12-06 05:32:45 UTC |
Source: | https://github.com/sammo3182/drhutools |
Packed ggplot2
function to compare the empirical cumulative distribution functions (ECDF) between the treatment and control groups in an experiment or quasi-experiment.
data |
A data.frame including two columns, one recording the outcome and the other recording the assignment. The assignment column must be named as |
ks_test |
A logical option to indicate whether to show the Kolmogorov-Smirnov test result in the bottom-right corner. The default value is FALSE. |
point_size |
An integer to indicate the size of the points at the largest difference. The default value is 3. |
point_color |
An character or function to indicate the color of the points at the largest difference. The default value is |
link_color |
An character or function to indicate the color of the link at the largest difference. The default value is |
A list of ggplot2
objects comparing the ECDFs between the control and treatment groups and identifying at most three largest differences.
data("PlantGrowth") plot_plant <- cdplot(PlantGrowth, ks_test = TRUE) plot_plant
data("PlantGrowth") plot_plant <- cdplot(PlantGrowth, ks_test = TRUE) plot_plant
Folder hierarchy creator for academic research
folderSystem()
folderSystem()
The function constructs a standardized folder hierarchy encompassing codes/
, data/
, output/
, paper/
, and document/
. These directories are designated for storing programming scripts, data sets, processed outputs, manuscript drafts (including related images and submission documents), and assorted materials, respectively. This organization facilitates easy retrieval of project components, ensuring that members of Dr. Hu's Amazing Team can efficiently navigate and manage shared resources. This structure is advocated for collaborative projects to maintain uniformity across team operations.
Local folders under the project's working directory.
Function to extract colors as hex codes.
gb_cols(...)
gb_cols(...)
... |
A character vector indicating the names of colors. Options includes "gold", "black", "orange", "red", "light green", "green", "light blue", "blue", "light grey", "grey", and "dark grey". |
A character of hex codes.
Function to interpolate a gold-black color palette.
gb_pal(palette = "main", reverse = FALSE, ...)
gb_pal(palette = "main", reverse = FALSE, ...)
palette |
A character vector indicating the name of palette in gb_palettes. Available palettes:
|
reverse |
A logic vector indicating whether the palette should be reversed; the default is FALSE. |
... |
Additional arguments to pass to |
A function that takes an integer argument (the required number of colors) and returns a character vector of colors interpolating the given sequence.
goodmap
function is designed to create interactive PNG Map or GIF Map from a provided data file.
It supports two types of maps: point
and polygon
.
The function can visualize data by either plotting points based on geographical coordinates
or highlighting regions polygon based on their administrative boundaries (province or city level).
Additionally, the function can generate animated that showcase the change of data.If the map type is point
, the color and size of the points will be determined by the
value_set
column in the data file, which means the different value of each point.
If the map type is polygon
, the color of the polygons will be determined by the average
value of the value_set
column for each city or province in the data file.
goodmap( data_file, type = "point", level = NULL, animate = FALSE, animate_var = NULL, map_center = c(35.8617, 104.1954), zoom_level = 4, color_type = "numeric", custom_colors = NULL, point_radius = 5, legend_opacity = 0.7, legend_name = NULL, width = 800, height = 900 )
goodmap( data_file, type = "point", level = NULL, animate = FALSE, animate_var = NULL, map_center = c(35.8617, 104.1954), zoom_level = 4, color_type = "numeric", custom_colors = NULL, point_radius = 5, legend_opacity = 0.7, legend_name = NULL, width = 800, height = 900 )
data_file |
Dataframe.
When generate point map, |
type |
A string specifying the type of map to generate. Options are |
level |
A string specifying the level of administrative boundaries for polygon maps.
Acceptable values are |
animate |
A logical value indicating whether to generate an animation from the maps. The default is FALSE. If animate is FALSE, the whole data will be generated as a PNG file. If animate is TRUE, an animation will be generated from all panel data, the animate_var must be assigned. |
animate_var |
A string specifying the variable to animate over.
The default is |
map_center |
A numeric vector of length 2 specifying the latitude and longitude
for the center of the map view. Default is |
zoom_level |
A numeric value specifying the zoom level for the map. Default is 3. |
color_type |
If the data is discrete, such as types or categories, choose |
custom_colors |
A vector of colors for customizing the color gradient. Default is |
point_radius |
A numeric value specifying the radius for point markers on point maps. Default is 5. |
legend_opacity |
A numeric value specifying the opacity of the legend. Default is 0.7. |
legend_name |
The name of the legend. Default is |
width |
A numeric value specifying the width of the map images. Default is 800. |
height |
A numeric value specifying the height of the map images. Default is 900. |
Image in the viewer.
goodmap( toy_poly, type = "polygon", level = "province" )
goodmap( toy_poly, type = "polygon", level = "province" )
A internal dataset providing city names and corresponding file names for mapping with Leaflet.
leafletcn.map.names
leafletcn.map.names
A data frame with city names and file names.
A data.frame object
Fill scale constructors for gold & black colors
scale_color_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)
scale_color_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)
palette |
A character vector indicating the name of palette in
|
discrete |
A logic vector indicating whether color aesthetic is discrete or not; the default is "main". |
reverse |
A logic vector indicating whether the palette should be reversed. |
... |
Additional arguments passed to |
No return value, called for modifying the appearance of the plot.
Color scale constructors for gold & black colors
scale_fill_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)
scale_fill_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)
palette |
A character vector indicating the name of palette in
|
discrete |
A logic vector indicating whether color aesthetic is discrete or not; the default is "main". |
reverse |
A logic vector indicating whether the palette should be reversed. |
... |
Additional arguments passed to |
No return value, called for modifying the appearance of the plot.
goodmap
A sample dataset designed to illustrate the functionality of the goodmap
function.
toy_poly
toy_poly
A geographic data frame with 6 rows and 5 variables:
Optional data identifier.
Prefectural names, required for city-level map plotting.
Provincial names, required for provincial-level map plotting.
A numeric vector used to group data for animated plotting.
Values used to fill each polygon in the map.
A data.frame object
Calculate psychological traits based on
traits(survey)
traits(survey)
survey |
Psychological survey data as a |
The current version can calculate the TOSCA-3SC scores and Grit-O score.
A data frame with trait scores for each observations
Duckworth, Angela L., Christopher Peterson, Michael D. Matthews, and Dennis R. Kelly. 2007. “Grit: Perseverance and Passion for Long-Term Goals.” Journal of Personality and Social Psychology 92(6): 1087–1101. doi:10.1037/0022-3514.92.6.1087.
Tangney, June P. 1990. “Assessing Individual Differences in Proneness to Shame and Guilt: Development of the Self-Conscious Affect and Attribution Inventory.” Journal of Personality and Social Psychology 59(1): 102–11. doi:10.1037/0022-3514.59.1.102.
column_names <- c("Q3|R3", "Q3|R4", "Q4|R3", "Q4|R4", "Q5|R5", "Q5|R6", "Q6|R3", "Q6|R4", "Q7|R3", "Q7|R4", "Q8|R5", "Q8|R6", "Q9|R5", "Q9|R6", "Q10|R5", "Q10|R6", "Q11|R5", "Q11|R6", "Q12|R3", "Q12|R4", "Q13|R3", "Q13|R4", "Q14|1", "Q15|1", "Q16|1", "Q17|1", "Q18|1", "Q19|1", "Q20|1", "Q21|1", "Q22|1", "Q23|1", "Q24|1", "Q25|1") toy_data <- data.frame(matrix(sample(1:5, 10 * length(column_names), replace = TRUE), ncol = length(column_names))) names(toy_data) <- column_names traits(toy_data)
column_names <- c("Q3|R3", "Q3|R4", "Q4|R3", "Q4|R4", "Q5|R5", "Q5|R6", "Q6|R3", "Q6|R4", "Q7|R3", "Q7|R4", "Q8|R5", "Q8|R6", "Q9|R5", "Q9|R6", "Q10|R5", "Q10|R6", "Q11|R5", "Q11|R6", "Q12|R3", "Q12|R4", "Q13|R3", "Q13|R4", "Q14|1", "Q15|1", "Q16|1", "Q17|1", "Q18|1", "Q19|1", "Q20|1", "Q21|1", "Q22|1", "Q23|1", "Q24|1", "Q25|1") toy_data <- data.frame(matrix(sample(1:5, 10 * length(column_names), replace = TRUE), ncol = length(column_names))) names(toy_data) <- column_names traits(toy_data)