knitr::opts_chunk$set( collapse = TRUE, comment = NA )
Our objective is to convert an output spectrum from a Monte Carlo simulation using PENEPMA into a R dataframe for analysis and other processing.
First we get our exemplar file.
spcPath <- system.file("extdata", "pe-spect-01.dat", package = "rpenepma") spcPath
Then we create an R dataframe using the penepma_read_raw_data
function.
library(rpenepma) library(pander) library(ggplot2) df <- penepma_read_raw_data(spcPath) rownames(df) <- c() pander(head(df))
and the tail
pander(tail(df))
pander(summary(df))
Now we are ready to plot the spectrum. There is a very large dynamic range for both the probability density and the uncertainty. Penepma sets a lower limit for data at 1.0e-35. Missing values are set to zero. We want to remove values from the dataframe that are below a useful limit. We do this below and plot a copy of the dataframe that is limited to the useful values.
plt <- ggplot(df, aes(x = keV, y = pd.mu)) + geom_line() + scale_x_continuous(breaks = seq(from = 0, to = 15, by = 1), limits = c(0,15)) + scale_y_log10() + xlab(label="X-ray energy [keV]") + ylab(label="probability density") + # (1/(eV*sr*electron)") + ggtitle('PENEPMA simulation of Corning EagleXG glass at 15 kV') + theme(axis.text=element_text(size=12), axis.title=element_text(size=12), # center the title plot.title = element_text(hjust = 0.5)) print(plt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.