<div dir="ltr">Sure, you can use the pdf() function before the par() one. As quartz(), pdf() allows to define the dimensions of the window. Instead of par(), the layout() function is great too to divide the window into several plots. The pdf() file is produced while R meets the dev.off() line after the commands generating the plots, the axes, and so on. <div><div><br></div><div><p class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p2" style="font-size:12.8px">pdf(file="working_directory/plots.pdf", height=, etc.)</p><p class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p2" style="font-size:12.8px">par(<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s4">mfrow</span>=c(<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s5">1</span>,<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s5">2</span>))</p><p class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p1" style="font-size:12.8px"><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s6">for</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">(</span>i<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s6">in</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span>stats<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">)</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">{</span></p><p class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p3" style="font-size:12.8px"><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2"> plot(</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s4">i</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">,</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s4">stat</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">=c(</span>"ASW"<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">,</span>"HC"<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">,</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span>"<wbr>R2"<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">,</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span>"PBC"<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">,</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span>"HG"<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">),</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s4">legendpos</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">=</span>"<wbr>topright"<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">,</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1"> </span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s4">norm</span><span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">=</span>"zscore"<span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">)</span></p><p class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p1" style="font-size:12.8px"></p><p class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p1" style="font-size:12.8px"> <span class="gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2">}</span></p></div><div>dev.off()</div><div><br></div><div><div>Best,</div><div>thomas</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-10-08 14:09 GMT+02:00 Reynolds, Jeremy E <span dir="ltr"><<a href="mailto:reyno113@purdue.edu" target="_blank">reyno113@purdue.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="auto">
<div>Thank you Thomas! It is amazing how many things a novice user can mess up in just a few lines. Loops and the apply functions seem to be a perenniaI source of confusion in R.</div>
<div id="m_4054072884049806692AppleMailSignature"><br>
</div>
<div id="m_4054072884049806692AppleMailSignature">I was hoping to save the plots in a single file (perhaps PDF?). Do you have any additional tips for that?</div>
<div id="m_4054072884049806692AppleMailSignature"><br>
</div>
<div id="m_4054072884049806692AppleMailSignature">Thanks</div>
<div id="m_4054072884049806692AppleMailSignature">Jeremy</div>
<div id="m_4054072884049806692AppleMailSignature"><br>
Sent from my iPhone</div><div><div class="h5">
<div><br>
On Oct 8, 2016, at 2:10 AM, thomas collas <<a href="mailto:thomas.collas@gmail.com" target="_blank">thomas.collas@gmail.com</a>> wrote:<br>
<br>
</div>
</div></div><blockquote type="cite">
<div>
<div dir="ltr"><div><div class="h5">Dear Jeremy,
<div>That should work if you change 3 things :</div>
<div>- the first problem is your stats object, which is a character vector, not a list of objects, you can't plot a character string.</div>
<div>- the second problem is the "x" in the plot function. If i is a component and not an attribute of stats, you can't index stats with i.</div>
<div>- the third smaller problem is that you have to ask R to print two plots. If it is only for visualization, you can use the mfrow argument in the par() function.</div>
<div><br>
</div>
<div>After having created the two objects you want to plot, this code should work :</div>
<div>
<p class="m_4054072884049806692gmail-m_6006289437679071460gmail-p1">stats<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2"><-</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">list(</span>pamomf2i5q.w<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">,</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s3"> </span>pa<wbr>mwardomf2i5q.w<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">)</span></p>
<p class="m_4054072884049806692gmail-m_6006289437679071460gmail-p2">par(<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s4">mfrow</span>=c(<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s5">1</span>,<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s5">2</span>))</p>
<p class="m_4054072884049806692gmail-m_6006289437679071460gmail-p1"><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s6">for</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">(</span>i<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s6">in</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span>stats<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">)</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">{</span></p>
<p class="m_4054072884049806692gmail-m_6006289437679071460gmail-p3"><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2"> plot(</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s4">i</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">,</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s4">stat</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">=c(</span>"ASW"<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">,</span>"HC"<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">,</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span>"<wbr>R2"<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">,</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span>"PBC"<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">,</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span>"HG"<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">),</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s4">legendpos</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">=</span>"<wbr>topright"<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">,</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s1"> </span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s4">norm</span><span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">=</span>"zscore"<span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">)</span></p>
<p class="m_4054072884049806692gmail-m_6006289437679071460gmail-p1"></p>
<p class="m_4054072884049806692gmail-m_6006289437679071460gmail-p1"> <span class="m_4054072884049806692gmail-m_6006289437679071460gmail-s2">}</span></p>
</div>
<div>Best,</div>
<div>thomas</div>
</div></div><div class="gmail_extra"><br>
<div class="gmail_quote"><div><div class="h5">2016-10-08 4:41 GMT+02:00 Reynolds, Jeremy E <span dir="ltr">
<<a href="mailto:reyno113@purdue.edu" target="_blank">reyno113@purdue.edu</a>></span>:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_4054072884049806692m_7376358845643935901WordSection1"><div><div class="h5">
<p class="MsoNormal">Dear TraMineR Users,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I would like to loop through many sets of clustering results produced with wcKMedRange and produce a plot for each one. Without the loop, the code would look like this:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">plot(pamomf2i5q.w, stat=c("ASWw","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<u></u><u></u></p>
<p class="MsoNormal">plot(pamwardomf2i5q.w, stat=c("ASWw","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">When I try to put this in a loop, I get the error messages below suggesting that R is expecting a y value in the plot command. Is there something wrong with my loop that is causing this problem?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Jeremy<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">> stats <- c("pamomf2i5q.w", "pamwardomf2i5q.w")<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">> for (i in unique(stats)) {<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+ plot(stats[i], stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+ }<u></u><u></u></span></p>
</div></div><p class="MsoNormal" style="background:#e5e5e5;word-break:break-all"><u></u><image001.png><u></u><span style="font-size:10.0pt;font-family:"Lucida Console";color:black"> Show Traceback<u></u><u></u></span></p><span class="">
<p class="MsoNormal" style="background:#e5e5e5;word-break:break-all"><span style="font-size:10.0pt;font-family:"Lucida Console";color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:#e5e5e5;word-break:break-all"><span style="font-size:10.0pt;font-family:"Lucida Console";color:black"> Rerun with Debug<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:#e5e5e5;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:#e5e5e5;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#c5060b">Error in plot.window(...) : need finite 'ylim' values<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:#e5e5e5;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#c5060b">In addition: Warning messages:<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#c5060b">1: In min(x) : no non-missing arguments to min; returning Inf<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#c5060b">2: In max(x) : no non-missing arguments to max; returning -Inf<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#c5060b">3: In plot.window(...) : "stat" is not a graphical parameter<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#c5060b">4: In plot.window(...) : "legendpos" is not a graphical parameter<u></u><u></u></span></p>
<p class="MsoNormal" style="line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#c5060b">5: In plot.window(...) : "norm" is not a graphical parameter</span><span style="font-size:10.0pt;font-family:"Lucida Console";color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</span></div>
</div><span class="">
<br>
______________________________<wbr>_________________<br>
Traminer-users mailing list<br>
<a href="mailto:Traminer-users@lists.r-forge.r-project.org" target="_blank">Traminer-users@lists.r-forge.r<wbr>-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users" rel="noreferrer" target="_blank">https://lists.r-forge.r-projec<wbr>t.org/cgi-bin/mailman/listinfo<wbr>/traminer-users</a><br>
</span></blockquote>
</div>
<br>
</div>
</div>
</div>
</blockquote><span class="">
<blockquote type="cite">
<div><span>______________________________<wbr>_________________</span><br>
<span>Traminer-users mailing list</span><br>
<span><a href="mailto:Traminer-users@lists.r-forge.r-project.org" target="_blank">Traminer-users@lists.r-forge.<wbr>r-project.org</a></span><br>
<span><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/traminer-users</a></span></div>
</blockquote>
</span></div>
<br>______________________________<wbr>_________________<br>
Traminer-users mailing list<br>
<a href="mailto:Traminer-users@lists.r-forge.r-project.org">Traminer-users@lists.r-forge.<wbr>r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/traminer-users</a><br></blockquote></div><br></div>