box plot using column of different length - r

I want to do some box plots, but I have data with a different number of rows for each column.
My data looks like:
OT1 OT2 OT3 OT4 OT5 OT6
22,6130653 16,6666667 20,259481 9,7431602 0,2777778 16,0678643
21,1122919 32,2946176 11,396648 10,9458023 4,7128509 10,8938547
23,5119048 19,5360195 23,9327541 39,5634921 0,6715507 12,2591613
16,9880885 39,5365943 7,7568134 22,7453205 3,6410445 11,7610063
32,768937 25,2897351 9,6288027 4,1629535 3,7251656
40,7819933 15,6320021 5,9171598
23,7961828 14,3728125 2,1887585
I'd like to have a box plot for each column (OT1, OT2…), but with the first three and the last three grouped together.
I tried:
>mydata <- read.csv('L5.txt', header = T, sep = "\t")
>mydata_t <- t(mydata)
>boxplot(mydata_t, ylab = "OTU abundance (%)",las=2, at=c(1,2,3 5,6,7))
But it didn't work…
How can I do?
Thanks!

Combining both answers and extenting Henrik's answer, you can also group the OT's together in boxplot() as well:
dat <- read.table(text='OT1 OT2 OT3 OT4 OT5 OT6
22,6130653 16,6666667 20,259481 9,7431602 0,2777778 16,0678643
21,1122919 32,2946176 11,396648 10,9458023 4,7128509 10,8938547
23,5119048 19,5360195 23,9327541 39,5634921 0,6715507 12,2591613
16,9880885 39,5365943 7,7568134 22,7453205 3,6410445 11,7610063
32,768937 25,2897351 9,6288027 4,1629535 3,7251656
40,7819933 15,6320021 5,9171598
23,7961828 14,3728125 2,1887585',header=TRUE,fill=TRUE)
dat <- sapply(dat,function(x)as.numeric(gsub(',','.',x)))
dat.m <- melt(dat)
dat.m <- transform(dat.m,group=ifelse(grepl('1|2|3','4|5|6'),
'group1','group2'))
as.factor(dat.m$X2)
boxplot(dat.m$value~dat.m$X2,data=dat.m,
axes = FALSE,
at = 1:6 + c(0.2, 0, -0.2),
col = rainbow(6))
axis(side = 1, at = c(2, 5), labels = c("Group_1", "Group_2"))
axis(side = 2, at = seq(0, 40, by = 10))
legend("topright", legend = c("OT1", "OT2", "OT3", "OT4", "OT5", "OT6"), fill = rainbow(6))
abline(v = 3.5, col = "grey")
box()

Not easy to group boxplots using R basic plots, better to use ggplot2 here. Whatever the difficulty here is how to reformat your data and reshape them in the long format.
dat <- read.table(text='OT1 OT2 OT3 OT4 OT5 OT6
22,6130653 16,6666667 20,259481 9,7431602 0,2777778 16,0678643
21,1122919 32,2946176 11,396648 10,9458023 4,7128509 10,8938547
23,5119048 19,5360195 23,9327541 39,5634921 0,6715507 12,2591613
16,9880885 39,5365943 7,7568134 22,7453205 3,6410445 11,7610063
32,768937 25,2897351 9,6288027 4,1629535 3,7251656
40,7819933 15,6320021 5,9171598
23,7961828 14,3728125 2,1887585',header=TRUE,fill=TRUE)
dat = sapply(dat,function(x)as.numeric(gsub(',','.',x)))
dat.m <- melt(dat)
dat.m <- transform(dat.m,group=ifelse(grepl('1|2|3',Var2),
'group1','group2'))
ggplot(dat.m)+
geom_boxplot(aes(x=group,y=value,fill=Var2))

Or with boxplot, using #agstudy's 'dat':
df <- melt(dat)
boxplot(value ~ Var2, data = df, at = 1:6 + c(0.2, 0, -0.2))

Related

Wireframe plot not showing the values [duplicate]

This question already has answers here:
R: Plotting a 3D surface from x, y, z
(5 answers)
Closed last year.
I am attempting to complete this wireframe plot, but for however reason it does not show the contents, only the outline of the plot. Below are data and MWE.
What am I doing wrong?
Uncooperative (πŸ˜‰) code:
library(lattice)
wireframe(
data = as.data.frame(a), ncpg12 ~ `S>B` * powg2,
shade = T, aspect = c(1, 1.5, 2), scales = list(arrows = F)
)
Data as wire.csv:
ncpg12,powg2,S>B
9.248631177619243,0.5604918536931173,0.00183393456426873
6.982877749338513,0.3098192715335432,0.01213195467163962
4.701116657737657,0.04999999999999999,0.06639433627763273
5.910427426924798,0.24518128912337697,0.1450446478654616
7.100787486648187,0.410018053934651,0.18041044252588423
6.867220052256016,0.5604978615437913,0.01213195467163977
4.557178781889888,0.3098192714867842,0.03131615691038152
2.256382318979377,0.04999999999999999,0.10386777520189128
3.544175197270306,0.24518128913433623,0.1956947037363749
4.786247297051887,0.4100180539207875,0.23509889193262204
4.47444787576751,0.5604978615358123,0.0663943362776329
2.1492331205663504,0.30981927148918764,0.10386777520189153
0,0.04999999999999999,0.2119180786856567
1.6301662903351826,0.24518128914507187,0.3267560369666459
3.046468068832837,0.4100180539377091,0.37248269710500553
5.731804609367828,0.5604978615356425,0.1450446478654616
3.4916627620168583,0.30981927144570615,0.19569470373637557
1.691074359432605,0.04999999999999999,0.32675603696664685
3.791287623813332,0.24518128912628456,0.4532575404720525
5.415642812939041,0.4100180538993808,0.5011596926023434
6.959612008409749,0.5604978614989732,0.1804104425258848
4.773824852643884,0.30981927143543664,0.2350988919326221
3.149864586948752,0.04999999999999999,0.3724826971050044
5.458051219009576,0.24518128905784495,0.5011596926023425
7.169432426981075,0.4100180538979537,0.5490511783213748
13.743971562458682,0.8475275485721443,0.00146994891912016
9.18463317316673,0.5431311708382447,0.01136908005754479
4.701116657905004,0.04999999999999999,0.06570438744198948
7.351968961351304,0.43391556095132944,0.14532454892964627
9.852982274307578,0.6876116333369463,0.1811890044398896
11.388418467186057,0.8475300860646717,0.01098668767881793
6.766360203153454,0.5431311707908197,0.02979799221541907
2.256382319061231,0.04999999999999999,0.10249311714271682
5.022962834042119,0.4339155609593038,0.19531930144010193
7.600496760083843,0.6876116333470675,0.23521845207420533
8.942010973938523,0.8475300860612255,0.06292370525775945
4.296879777810318,0.5431311707936094,0.10016997191686286
0,0.04999999999999999,0.2086924088558675
3.259433943545446,0.4339155609421589,0.32472076124519667
6.08980889108534,0.6876116333444386,0.37097763013907503
10.033463255787863,0.8475300860611537,0.13933895061160378
5.50333769575991,0.5431311708127886,0.18999713514627453
1.691074359241611,0.04999999999999999,0.3220093974091579
5.616303463568329,0.43391556093219097,0.449989511559725
8.743466363001062,0.687611633342467,0.4984905017778514
11.174209234632144,0.8475300860623024,0.1739366597649558
6.717756648919021,0.5431311708061631,0.22874296954077433
3.149864587112461,0.04999999999999999,0.3672893695383088
7.367578939567466,0.4339155609391685,0.4975672654509311
10.617837423260426,0.6876116333328715,0.5460864990319658
Here's how I would do it.
dat <- read.csv(textConnection("'ncpg12','powg2','S>B',
9.248631177619243,0.5604918536931173,0.00183393456426873
6.982877749338513,0.3098192715335432,0.01213195467163962
4.701116657737657,0.04999999999999999,0.06639433627763273
5.910427426924798,0.24518128912337697,0.1450446478654616
7.100787486648187,0.410018053934651,0.18041044252588423
6.867220052256016,0.5604978615437913,0.01213195467163977
4.557178781889888,0.3098192714867842,0.03131615691038152
2.256382318979377,0.04999999999999999,0.10386777520189128
3.544175197270306,0.24518128913433623,0.1956947037363749
4.786247297051887,0.4100180539207875,0.23509889193262204
4.47444787576751,0.5604978615358123,0.0663943362776329
2.1492331205663504,0.30981927148918764,0.10386777520189153
0,0.04999999999999999,0.2119180786856567
1.6301662903351826,0.24518128914507187,0.3267560369666459
3.046468068832837,0.4100180539377091,0.37248269710500553
5.731804609367828,0.5604978615356425,0.1450446478654616
3.4916627620168583,0.30981927144570615,0.19569470373637557
1.691074359432605,0.04999999999999999,0.32675603696664685
3.791287623813332,0.24518128912628456,0.4532575404720525
5.415642812939041,0.4100180538993808,0.5011596926023434
6.959612008409749,0.5604978614989732,0.1804104425258848
4.773824852643884,0.30981927143543664,0.2350988919326221
3.149864586948752,0.04999999999999999,0.3724826971050044
5.458051219009576,0.24518128905784495,0.5011596926023425
7.169432426981075,0.4100180538979537,0.5490511783213748
13.743971562458682,0.8475275485721443,0.00146994891912016
9.18463317316673,0.5431311708382447,0.01136908005754479
4.701116657905004,0.04999999999999999,0.06570438744198948
7.351968961351304,0.43391556095132944,0.14532454892964627
9.852982274307578,0.6876116333369463,0.1811890044398896
11.388418467186057,0.8475300860646717,0.01098668767881793
6.766360203153454,0.5431311707908197,0.02979799221541907
2.256382319061231,0.04999999999999999,0.10249311714271682
5.022962834042119,0.4339155609593038,0.19531930144010193
7.600496760083843,0.6876116333470675,0.23521845207420533
8.942010973938523,0.8475300860612255,0.06292370525775945
4.296879777810318,0.5431311707936094,0.10016997191686286
0,0.04999999999999999,0.2086924088558675
3.259433943545446,0.4339155609421589,0.32472076124519667
6.08980889108534,0.6876116333444386,0.37097763013907503
10.033463255787863,0.8475300860611537,0.13933895061160378
5.50333769575991,0.5431311708127886,0.18999713514627453
1.691074359241611,0.04999999999999999,0.3220093974091579
5.616303463568329,0.43391556093219097,0.449989511559725
8.743466363001062,0.687611633342467,0.4984905017778514
11.174209234632144,0.8475300860623024,0.1739366597649558
6.717756648919021,0.5431311708061631,0.22874296954077433
3.149864587112461,0.04999999999999999,0.3672893695383088
7.367578939567466,0.4339155609391685,0.4975672654509311
10.617837423260426,0.6876116333328715,0.5460864990319658"), header=TRUE)
names(dat) <- c("ncpg12", "powg2", "SB")
library(rgl)
s <- interp(dat$powg2, dat$SB, dat$ncpg12)
eg <- expand.grid(xind = 1:40,
yind = 1:40)
eg$powg2 <- s$x[eg$xind]
eg$SB <- s$y[eg$yind]
eg$ncpg12 <- c(s$z)
library(lattice)
wireframe(
data = eg,
ncpg12 ~ SB * powg2,
shade = T, aspect = c(1, 1.5, 2), scales = list(arrows = F)
)

Error "not numeric" when using crosstalk package with EnhancedVolcano

I'd like to implement a cross-talk functionality between a table and plot in both directions:
select the row in the table which will be reflected in the plot
select a dot in the plot which will be reflected in the table. Same idea as here.
I've managed to implement a script, which works beautifully if I make scatter plot with ggplot() and table (both objects cross-talk!). However, when used EnhancedVolcano() and table I got the following error:
Error in EnhancedVolcano(toptable = data_shared, lab = "disp", x = "qsec", :
qsec is not numeric!
If I replace data_shared variable with df_orig, no error is raised, but there is no cross-talking between objects :(
Does this mean that SharedData$new() doesn't recognize numeric values as numeric? How to fix this error?
Any help is highly appreciated.
Thank you
Toy example:
library(plotly) # '4.9.1'
library(DT) # '0.11'
library(crosstalk) # β€˜1.0.0’
library(EnhancedVolcano) # β€˜1.4.0’
# Input
data1 = mtcars #dim(data1) # 32 11
data_shared = SharedData$new(data1) #, key = c("qsec", "hp"))
# df_orig = data_shared$origData()
# V-Plot
vp =EnhancedVolcano( toptable = data_shared,
lab = 'disp',
x = 'qsec',
y = 'hp',
xlab ='testX',
ylab = 'testY')
bscols(
ggplotly(vp + aes(x= qsec, y= -log10(hp/1000))),
datatable(data_shared, style="bootstrap", class="compact", width="100%",
options=list(deferRender=FALSE, dom='t')))
Same script, which works with ggplot():
data1 = mtcars #dim(data1) # 32 11
data_shared = SharedData$new(data1)
vp = ggplot(data = data_shared, mapping = aes(qsec, hp)) +
geom_point()
bscols(
ggplotly(vp) ,
datatable(data_shared, style="bootstrap", class="compact", width="100%",
options=list(deferRender=FALSE, dom='t')))
Note: Related (same) question was posted at BioStars, and the package author posted an answer, with author's permission copying an answer here:
Hi,
Thanks - that's very useful code and I may add it to the main package vignette, eventually.
I tried it here on my computer and I was able to get it working in my browser, but some components of the original plot seem to have been lost. I think that you just need to convert your column, 'qsec', to numerical values.
Re-using an example from my Vignette, here is a perfectly reproducible example:
library("pasilla")
pasCts <- system.file("extdata", "pasilla_gene_counts.tsv",
package="pasilla", mustWork=TRUE)
pasAnno <- system.file("extdata", "pasilla_sample_annotation.csv",
package="pasilla", mustWork=TRUE)
cts <- as.matrix(read.csv(pasCts,sep="\t",row.names="gene_id"))
coldata <- read.csv(pasAnno, row.names=1)
coldata <- coldata[,c("condition","type")]
rownames(coldata) <- sub("fb", "", rownames(coldata))
cts <- cts[, rownames(coldata)]
library("DESeq2")
dds <- DESeqDataSetFromMatrix(countData = cts,
colData = coldata,
design = ~ condition)
featureData <- data.frame(gene=rownames(cts))
mcols(dds) <- DataFrame(mcols(dds), featureData)
dds <- DESeq(dds)
res <- results(dds)
library(EnhancedVolcano)
p1 <- EnhancedVolcano(res,
lab = rownames(res),
x = "log2FoldChange",
y = "pvalue",
pCutoff = 10e-4,
FCcutoff = 2,
xlim = c(-5.5, 5.5),
ylim = c(0, -log10(10e-12)),
pointSize = c(ifelse(res$log2FoldChange>2, 8, 1)),
labSize = 4.0,
shape = c(6, 6, 19, 16),
title = "DESeq2 results",
subtitle = "Differential expression",
caption = "FC cutoff, 1.333; p-value cutoff, 10e-4",
legendPosition = "right",
legendLabSize = 14,
col = c("grey30", "forestgreen", "royalblue", "red2"),
colAlpha = 0.9,
drawConnectors = TRUE,
hline = c(10e-8),
widthConnectors = 0.5)
p1 <- p1 +
ggplot2::coord_cartesian(xlim=c(-6, 6)) +
ggplot2::scale_x_continuous(
breaks=seq(-6,6, 1))
library(plotly)
library(DT)
library(crosstalk)
bscols(
ggplotly(p1 + aes(x= log2FoldChange, y= -log10(pvalue))),
datatable(
data.frame(res),
style="bootstrap",
class="compact", width="100%",
options=list(deferRender=FALSE, dom='t')))
Unfortunately, plotly and/or bscols don't like the use of bquote(), so, one cannot have the fancy axes names that I use in EnhancedVolcano:
... + xlab(bquote(~Log[2] ~ "fold change")) + ylab(bquote(~-Log[10] ~ italic(P)))
When i try to add these, it throws an error.
Kevin
tried to modify few things in volcano function, got following error:
Error in as.data.frame.default(toptable) :
cannot coerce class β€˜c("SharedData", "R6")’ to a data.frame
not sure yet, how to fix it.

plot(var()) displays two different plots, how do I merge them into one? Also having two y axis

> dput(head(inputData))
structure(list(Date = c("2018:07:00", "2018:06:00", "2018:05:00",
"2018:04:00", "2018:03:00", "2018:02:00"), IIP = c(125.8, 127.5,
129.7, 122.6, 140.3, 127.4), CPI = c(139.8, 138.5, 137.8, 137.1,
136.5, 136.4), `Term Spread` = c(1.580025, 1.89438, 2.020112,
1.899074, 1.470544, 1.776862), RealMoney = c(142713.9916, 140728.6495,
140032.2762, 139845.5215, 139816.4682, 139625.865), NSE50 = c(10991.15682,
10742.97381, 10664.44773, 10472.93333, 10232.61842, 10533.10526
), CallMoneyRate = c(6.161175, 6.10112, 5.912088, 5.902226, 5.949956,
5.925538), STCreditSpread = c(-0.4977, -0.3619, 0.4923, 0.1592,
0.3819, -0.1363)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
I want to make my autoregressive plot like this plot:
#------> importing all libraries
library(readr)
install.packages("lubridtae")
library("lubridate")
install.packages("forecast")
library('ggplot2')
library('fpp')
library('forecast')
library('tseries')
#--------->reading data
inputData <- read_csv("C:/Users/sanat/Downloads/exercise_1.csv")
#--------->calculating the lag=1 for NSE50
diff_NSE50<-(diff(inputData$NSE50, lag = 1, differences = 1)/lag(inputData$NSE50))
diff_RealM2<-(diff(inputData$RealMoney, lag = 1, differences = 1)/lag(inputData$RealMoney))
plot.ts(diff_NSE50)
#--------->
lm_fit = dynlm(IIP ~ CallMoneyRate + STCreditSpread + diff_NSE50 + diff_RealM2, data = inputData)
summary(lm_fit)
#--------->
inputData_ts = ts(inputData, frequency = 12, start = 2012)
#--------->area of my doubt is here
VAR_data <- window(ts.union(ts(inputData$IIP), ts(inputData$CallMoneyRate)))
VAR_est <- VAR(y = VAR_data, p = 12)
plot(VAR_est)
I want to my plots to get plotted together in same plot. How do I serparate the var() plots to two separate ones.
Current plot:
My dataset :
dataset
Okay, so this still needs some work, but it should set the right framework for you. I would look more into working with the ggplot2 for future.
Few extra packages needed, namely library(vars) and library(dynlm).
Starting from,
VAR_est <- VAR(y = VAR_data, p = 12)
Now we extract the values we want from the VAR_est object.
y <- as.numeric(VAR_est$y[,1])
z <- as.numeric(VAR_est$y[,2])
x <- 1:length(y)
## second data set on a very different scale
par(mar = c(5, 4, 4, 4) + 0.3) # Leave space for z axis
plot(x, y, type = "l") # first plot
par(new = TRUE)
plot(x, z, type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "")
axis(side=4, at = pretty(range(z)))
mtext("z", side=4, line=3)
I will leave you to add the dotted lines on etc...
Hint: Decompose the VAR_est object, for example, VAR_est$datamat, then see which bit of data corresponds to the part of the plot you want.
Used some of this

Loop functions with multiple variables for ggplot2

I want to build several plots from one large database, so that I have one plot for each Text (factor) and for each Measure (the many resulting measures of an eye tracking study). The following is a much simpler example of what I am trying to to:
Let's say this is my dataset
Text <- c(1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2)
Position <- c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
Modified <- c(1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0)
Line_on_page <- c(1, 1, 1, 1, 2,2,2,2 ,1 ,1,1,1,2,2,2,2)
IA_FIXATION_DURATION <- c(250.3, 70.82, 400, 120.12, 270, 120.5, 100.54, 212.43, 250.3, 70.82, 320.29, 123.12, 260, 121.5, 100.54, 272.43)
IA_FIXATION_COUNT <- c(1,0,1,1,3,2,0, 1, 1,0,1,2,3,2,0, 2)
IA_LABEL <- c("she", "did", "not", "know", "what", "to", "say", "to", "she", "did", "not", "know", "what", "to", "do", "to")
testDF <- data.frame(Text , Position , Line_on_page, Modified, IA_FIXATION_DURATION, IA_FIXATION_COUNT, IA_LABEL)
so I want a heatmap (or another graph) for each Text (1/2/3), and for each measure (IA_FIXATION_DURATION/IA_FIXATION_COUNT)
# so first i create my vectors
library(stringr)
library(reshape2)
library(ggplot2)
library(ggthemes)
library(tidyverse)
Text_list <- unique(testDF$Text)
Measure_list <- testDF %>% dplyr::select_if(is.numeric) %>% colnames() %>% as.vector()
# create graphing function
Heatmap_FN <- function(testDF, na.rm = TRUE, ...){
# create for loop to produce ggplot2 graphs
for (i in seq_along(Text_list)) {
for (j in seq_along(Measure_list)) {
# create plot for each text in dataset
plots <- ggplot(subset(testDF, testDF$Text==Text_list[i])) +
geom_tile(aes(x=Position,
y=Line_on_page,
fill = Measure_list[j])) +
geom_text(aes(x=Position,
y=Line_on_page,
label=IA_LABEL),
color = "white", size = 2, family = "sans") +
scale_fill_viridis_c(option = "C", na.value = "black") +
scale_y_reverse() +
facet_grid(Page ~ Modified)+
theme(legend.position = "bottom") +
ggtitle(paste(Text_list[i],j, 'Text \n'))
ggsave(plots, file=paste(Measure_list[j], "_T", Text_list[i], ".pdf", sep = ""), height = 8.27, width = 11.69, units = c("in"))
}
}
}
Heatmap_FN(testDF)
now, I am pretty sure that the problem lies in the geom_tile "fill" part, where I would like to indicate to the function that I want to use the results variables one by one to produce the plot.
Any ideas on how to fix that?
Thanks

Saving multiply pdf plots r

I have made a loop for making multiply plots, however i have no way of saving them, my code looks like this:
#----------------------------------------------------------------------------------------#
# RING data: Mikkel
#----------------------------------------------------------------------------------------#
# Set working directory
setwd()
#### Read data & Converting factors ####
dat <- read.table("Complete RING.txt", header =TRUE)
str(dat)
dat$Vial <- as.factor(dat$Vial)
dat$Line <- as.factor(dat$Line)
dat$Fly <- as.factor(dat$Fly)
dat$Temp <- as.factor(dat$Temp)
str(dat)
datSUM <- summaryBy(X0.5_sec+X1_sec+X1.5_sec+X2_sec+X2.5_sec+X3_sec~Vial_nr+Concentration+Sex+Line+Vial+Temp,data=dat, FUN=sum)
fl<-levels(datSUM$Line)
colors = c("#e41a1c", "#377eb8", "#4daf4a", "#984ea3")
meltet <- melt(datSUM, id=c("Concentration","Sex","Line","Vial", "Temp", "Vial_nr"))
levels(meltet$variable) <- c('0,5 sec', '1 sec', '1,5 sec', '2 sec', '2,5 sec', '3 sec')
meltet20 <- subset(meltet, Line=="20")
meltet20$variable <- as.factor(meltet20$variable)
AllConcentrations <- levels(meltet20$Concentration)
for (i in AllConcentrations) {
meltet.i <- meltet20[meltet20$Concentration ==i,]
quartz()
print(dotplot(value~variable|Temp, group=Sex, data = meltet.i ,xlab="Time", ylab="Total height pr vial [mm above buttom]", main=paste('Line 20 concentration ', meltet.i$Concentration[1]),
key = list(points = list(col = colors[1:2], pch = c(1, 2)),
text = list(c("Female", "Male")),
space = "top"), col = colors, pch =c(1, 2))) }
I have tried with the quartz.save function, but that just overwrites the files. Im using a mac if that makes any difference.
When I want to save multiple plots in a loop I tend to do something like...
for(i in AllConcentrations){
meltet.i <- meltet20[meltet20$Concentration ==i,]
pdf(paste("my_filename", i, ".pdf", sep = ""))
dotplot(value~variable|Temp, group=Sex, data = meltet.i ,xlab="Time", ylab="Total height pr vial [mm above buttom]", main=paste('Line 20 concentration ', meltet.i$Concentration[1]),
key = list(points = list(col = colors[1:2], pch = c(1, 2)),
text = list(c("Female", "Male")),
space = "top"), col = colors, pch =c(1, 2))
dev.off()
}
This will create a pdf file for every level in AllConcentrations and save it in your working directory. It will paste together my_filename, the number of the iteration i, and then .pdf together to make each file unique. Of course, you will want to adjust height and width in the pdf function.

Resources