knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
tidyNano is a package that imports raw Nanosight data and faciliates the process of tidying the data so it is suitable for visualizing with ggplot2 and data manipulation with dplyr. tidyNano also has functions to facilitate the rapid generation of summary statistics by groups to assist with calculating technical replicate and within group mean, standard deviation, and standard error.
library(tidyNano) library(ggplot2) library(dplyr) library(tidyr)
This is an example raw Nanosight .csv output file and is not easily imported with read.csv()
file <- system.file("extdata", "beads.csv", package = "tidyNano") read.csv(file) %>% head()
nanoimport
is a function that extracts the particle data from raw a nanosight .csv file and creates a dataframe that is suitable for cleaning within R. Note: This assumes you added the dilution factor when you named your samples during acquistion.
data <- nanoimport(file) head(data)
If you didn't include your dilution factor in the sample name you can use the argument auto_name == TRUE
within the nanoimport()
function.
file2 <- system.file("extdata", "beads2.csv", package = "tidyNano") data2 <- nanoimport(file2, auto_name = TRUE) head(data2)
You can even add a custom name to append extra information to your sample columns using the custom_name()
argument.
custom_name_data2 <- nanoimport(file2, auto_name = TRUE, custom_name = "YourLabelHere") head(custom_name_data2)
nanotidy
is a function that facilitates the conversion of a dataframe to make it tidy for easy data visualization with ggplot2 and data manipulation with dplyr.
tidy_data <- nanoimport(file) %>% nanotidy( sep_var = c("Sample", "Dilution","Filter", "Injection","Tech_rep")) head(tidy_data)
Once the data is in the tidy format it can be easily visualized using existing libraries such as ggplot2.
tidy_data %>% ggplot(aes(x = particle_size, y = True_count, color = Tech_rep)) + geom_line(size = 1) + facet_wrap(Injection ~ Filter)
nanolyze
is a function that is able to quickly summarize data by groups. The first argument is the number of variables to group by. The second argument name is the prefix that is added to the mean, sd and se summary, the default name is "Param". The third argument is param_var which is the numeric variable that is to be summarized. The output of this function is a dataframe of the grouped variables, column N with number of values that were summarized, column mean for the mean, column sd for standard deviation, and column se for standard error of the mean. Here we see that the technical replicates will be averaged.
Tech_avg_data <- tidy_data %>% nanolyze(particle_size, Sample, Dilution, Filter, Injection, name = "Tech_rep", param_var = True_count) head(Tech_avg_data)
The technical average data can be visualized with ggpplot2.
Tech_avg_data %>% ggplot(aes(x = particle_size, y = Tech_rep_mean, color = Injection)) + geom_line( size = 1) + facet_wrap(~ Filter) + theme_bw()
In this experiment, a sample was read twice by the Nanosight and thus we can average the means by Injection to obtain a single mean value by using the nanolyze
function again. Notice the different use of the name
and param_var
arguments.
Injection_avg_data <- Tech_avg_data %>% nanolyze(particle_size, Sample, Dilution, Filter, name = "Injection", param_var = Tech_rep_mean) head(Injection_avg_data)
We can again use ggplot2 to visualize the mean injection data.
Injection_avg_data %>% ggplot(aes(x = particle_size, y = Injection_mean, color = Filter)) + geom_line( size = 1) + facet_wrap(~Filter)
We can also use dplyr to filter on values less than 300nm easily.
Injection_avg_data %>% filter(particle_size <300) %>% ggplot(aes(x = particle_size, y = Injection_mean, color = Filter)) + geom_line( size = 1) + facet_wrap(~Filter)
nanocount
is a function that is able to calculate the total sum of particles by group.
Injection_avg_data %>% nanocount(Sample, Dilution, Filter, param_var = Injection_mean)
We can also use dplyr verbs before nanocount. To calculate the total number of particles less than 100nm the filter command can be used.
Injection_avg_data %>% filter(particle_size < 100) %>% nanocount(Sample, Dilution, Filter, param_var = Injection_mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.