Title: | Summary Table and Means Plots |
---|---|
Description: | Optimized for handling complex datasets in environmental and ecological research, this package offers functionality that is not fully met by general-purpose packages. It provides two key functions, 'summarize_data()', which summarizes datasets, and 'plot_means()', which creates plots with error bars. The 'plot_means()' function incorporates error bars by default, allowing quick visualization of uncertainties, crucial in ecological studies. It also streamlines workflows for grouped datasets (e.g., by species or treatment), making it particularly user-friendly and reducing the complexity and time required for data summarization and visualization. |
Authors: | Oswald Omuron [aut, cre] |
Maintainer: | Oswald Omuron <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2025-03-09 05:11:01 UTC |
Source: | https://github.com/oswaldomuron/kifidi |
Kifidi v.0.1.0
Package: Kifidi
Type: Package
Title: Kifidi v.0.1.0
Version: 0.1.0
Author: Oswald Omuron
Maintainer: Oswald Omuron <[email protected]>
Description: An overview of how to use the package, including the most important functions under See Also below.
License: GPL-3
Oswald Omuron
Maintainer: Oswald Omuron <[email protected]>
https://github.com/OswaldOmuron/Kifidi
Optional links to other man pages, e.g. summarize_data
,
plot_means
This function calculates the frequency of each unique value in a given column of data, excluding NA
values.
counts(column_data)
counts(column_data)
column_data |
A vector of data (numeric, character, or factor) from which the unique groups and their frequencies are calculated. |
The function first removes any NA
values from the input data and identifies the unique groups.
It then counts the occurrences of each unique value and returns the results as a data frame with two columns: group
(the unique values) and counts
(their respective frequencies).
A data frame with the following components:
group |
The unique values from the input data. |
counts |
The frequency of each unique value. |
This function is intended for small to medium-sized datasets. For larger datasets, consider using table
for better performance.
Oswald Omuron
For additional information on related functions, see unique
and table
in base R.
# Example usage of counts function data <- c("A", "B", "A", "C", "B", "B", NA, "A", "C") result <- counts(data) print(result) # Output should look like: # group counts # 1 A 3 # 2 B 3 # 3 C 2
# Example usage of counts function data <- c("A", "B", "A", "C", "B", "B", NA, "A", "C") result <- counts(data) print(result) # Output should look like: # group counts # 1 A 3 # 2 B 3 # 3 C 2
This function plots the means of a summary data frame with optional error bars.
plot_means(summary_df, main_title = "Mean Values by Group", ylab = NULL, xlab = NULL, bar_color = "skyblue", error_bar_color = "red", bar_width = 0.7, error_bar_length = 0.1, axes = TRUE, space = NULL, density = NULL, angle = 45, col = NULL, names_arg = NULL, xlab_custom = NULL, ylab_custom = NULL, ann = TRUE, xlim = NULL, ylim = NULL, xaxt = "s", las = NULL)
plot_means(summary_df, main_title = "Mean Values by Group", ylab = NULL, xlab = NULL, bar_color = "skyblue", error_bar_color = "red", bar_width = 0.7, error_bar_length = 0.1, axes = TRUE, space = NULL, density = NULL, angle = 45, col = NULL, names_arg = NULL, xlab_custom = NULL, ylab_custom = NULL, ann = TRUE, xlim = NULL, ylim = NULL, xaxt = "s", las = NULL)
summary_df |
A summary data frame containing the means and standard errors for each group. |
main_title |
Main title for the plot. Default is "Mean Values by Group". |
ylab |
Label for the y-axis. |
xlab |
Label for the x-axis. |
bar_color |
Color for the bars. Default is "skyblue". |
error_bar_color |
Color for the error bars. Default is "red". |
bar_width |
Width of the bars. Default is 0.7. |
error_bar_length |
Length of the error bars. Default is 0.1. |
axes |
Logical value indicating whether to draw axes on the plot. Default is TRUE. |
space |
Spacing between bars. |
density |
Density of shading lines. |
angle |
Angle of shading lines. |
col |
Color of shading lines. |
names_arg |
Vector of names for the x-axis. |
xlab_custom |
Custom label for the x-axis. Default is "Groups". |
ylab_custom |
Custom label for the y-axis. Default is "Mean". |
ann |
Logical value indicating whether to draw annotations on the plot. Default is TRUE. |
xlim |
Limits for the x-axis. |
ylim |
Limits for the y-axis. |
xaxt |
Type of x-axis labeling. |
las |
Style of axis labels. |
If the summary data frame contains two grouping variables (Group1 and Group2), they will be combined to form the x-axis labels.
This function produces a bar plot with optional error bars.
Additional notes can be added here.
Oswald Omuron
Please refer to the documentation of the barplot
and arrows
functions in the base R package.
The summary
function for creating summary data frames.
# Example data example_data <- c( 445, 372, 284, 247, 328, 98.8, 108.7, 100.8, 123.6, 129.9, 133.3, 130.1, 123.1, 186.6, 215, 19.4, 19.3, 27.8, 26, 22, 30.9, 19.8, 16.5, 20.2, 31, 21.1, 16.5, 19.7, 18.9, 27, 161.8, 117, 94.6, 97.5, 142.7, 109.9, 118.3, 111.4, 96.5, 109, 114.1, 114.9, 101.2, 112.7, 111.1, 194.8, 169.9, 159.1, 100.8, 130.8, 93.6, 105.7, 178.4, 203, 172.2, 127.3, 128.3, 110.9, 124.1, 179.1, 293, 197.5, 139.1, 98.1, 84.6, 81.4, 87.2, 71.1, 70.3, 120.4, 194.5, 167.5, 121, 86.5, 81.7 ) example_group1 <- c( rep("Palm", 15), rep("Papyrus", 10), rep("Typha", 15), rep("Eucalyptus", 15), rep("Rice farm", 20) ) example_group2 <- rep(c(50, 40, 30, 20, 10), 15) # Create dataframe example_df <- data.frame( Vegetation_types = example_group1, Depth_revised = example_group2, EC_uS_cm = example_data ) # Summarize by one grouping variable summary_one_group <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types ) print(summary_one_group) # Summarize by two grouping variables summary_two_groups <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types, example_df$Depth_revised ) print(summary_two_groups) # Plotting the summarized data plot_means(summary_two_groups, ylim=c(0,350), las=2, space = c(0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0) )
# Example data example_data <- c( 445, 372, 284, 247, 328, 98.8, 108.7, 100.8, 123.6, 129.9, 133.3, 130.1, 123.1, 186.6, 215, 19.4, 19.3, 27.8, 26, 22, 30.9, 19.8, 16.5, 20.2, 31, 21.1, 16.5, 19.7, 18.9, 27, 161.8, 117, 94.6, 97.5, 142.7, 109.9, 118.3, 111.4, 96.5, 109, 114.1, 114.9, 101.2, 112.7, 111.1, 194.8, 169.9, 159.1, 100.8, 130.8, 93.6, 105.7, 178.4, 203, 172.2, 127.3, 128.3, 110.9, 124.1, 179.1, 293, 197.5, 139.1, 98.1, 84.6, 81.4, 87.2, 71.1, 70.3, 120.4, 194.5, 167.5, 121, 86.5, 81.7 ) example_group1 <- c( rep("Palm", 15), rep("Papyrus", 10), rep("Typha", 15), rep("Eucalyptus", 15), rep("Rice farm", 20) ) example_group2 <- rep(c(50, 40, 30, 20, 10), 15) # Create dataframe example_df <- data.frame( Vegetation_types = example_group1, Depth_revised = example_group2, EC_uS_cm = example_data ) # Summarize by one grouping variable summary_one_group <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types ) print(summary_one_group) # Summarize by two grouping variables summary_two_groups <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types, example_df$Depth_revised ) print(summary_two_groups) # Plotting the summarized data plot_means(summary_two_groups, ylim=c(0,350), las=2, space = c(0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0) )
This function summarizes the provided data column by one or two grouping variables. It calculates the mean, standard deviation, sample size, minimum, maximum, median, and standard error.
summarize_data(column_data, group_var1, group_var2 = NULL)
summarize_data(column_data, group_var1, group_var2 = NULL)
column_data |
A numeric vector containing the data to be summarized. |
group_var1 |
A factor or vector to group the data by. |
group_var2 |
An optional second factor or vector to group the data by. |
If only one grouping variable is provided, the function will summarize the data by that variable. If two grouping variables are provided, it will summarize the data by both variables.
A data frame with the following columns:
The first grouping variable (from group_var1
).
The second grouping variable (from group_var2
), if provided.
The mean of the column_data
for each group.
The standard deviation of the column_data
for each group.
The sample size for each group.
The minimum value of the column_data
for each group.
The maximum value of the column_data
for each group.
The median value of the column_data
for each group.
The standard error of the mean for each group.
A data frame with the above columns.
The grouping variables and the data column can be of different lengths.
Oswald Omuron
No references available.
# Example data example_data <- c( 445, 372, 284, 247, 328, 98.8, 108.7, 100.8, 123.6, 129.9, 133.3, 130.1, 123.1, 186.6, 215, 19.4, 19.3, 27.8, 26, 22, 30.9, 19.8, 16.5, 20.2, 31, 21.1, 16.5, 19.7, 18.9, 27, 161.8, 117, 94.6, 97.5, 142.7, 109.9, 118.3, 111.4, 96.5, 109, 114.1, 114.9, 101.2, 112.7, 111.1, 194.8, 169.9, 159.1, 100.8, 130.8, 93.6, 105.7, 178.4, 203, 172.2, 127.3, 128.3, 110.9, 124.1, 179.1, 293, 197.5, 139.1, 98.1, 84.6, 81.4, 87.2, 71.1, 70.3, 120.4, 194.5, 167.5, 121, 86.5, 81.7 ) example_group1 <- c( rep("Palm", 15), rep("Papyrus", 10), rep("Typha", 15), rep("Eucalyptus", 15), rep("Rice farm", 20) ) example_group2 <- rep(c(50, 40, 30, 20, 10), 15) # Create dataframe example_df <- data.frame( Vegetation_types = example_group1, Depth_revised = example_group2, EC_uS_cm = example_data ) # Summarize by one grouping variable summary_one_group <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types ) print(summary_one_group) # Summarize by two grouping variables summary_two_groups <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types, example_df$Depth_revised ) print(summary_two_groups)
# Example data example_data <- c( 445, 372, 284, 247, 328, 98.8, 108.7, 100.8, 123.6, 129.9, 133.3, 130.1, 123.1, 186.6, 215, 19.4, 19.3, 27.8, 26, 22, 30.9, 19.8, 16.5, 20.2, 31, 21.1, 16.5, 19.7, 18.9, 27, 161.8, 117, 94.6, 97.5, 142.7, 109.9, 118.3, 111.4, 96.5, 109, 114.1, 114.9, 101.2, 112.7, 111.1, 194.8, 169.9, 159.1, 100.8, 130.8, 93.6, 105.7, 178.4, 203, 172.2, 127.3, 128.3, 110.9, 124.1, 179.1, 293, 197.5, 139.1, 98.1, 84.6, 81.4, 87.2, 71.1, 70.3, 120.4, 194.5, 167.5, 121, 86.5, 81.7 ) example_group1 <- c( rep("Palm", 15), rep("Papyrus", 10), rep("Typha", 15), rep("Eucalyptus", 15), rep("Rice farm", 20) ) example_group2 <- rep(c(50, 40, 30, 20, 10), 15) # Create dataframe example_df <- data.frame( Vegetation_types = example_group1, Depth_revised = example_group2, EC_uS_cm = example_data ) # Summarize by one grouping variable summary_one_group <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types ) print(summary_one_group) # Summarize by two grouping variables summary_two_groups <- summarize_data( example_df$EC_uS_cm, example_df$Vegetation_types, example_df$Depth_revised ) print(summary_two_groups)