[Traminer-users] loop for plotting quality statistics from wcKMedRange
Reynolds, Jeremy E
reyno113 at purdue.edu
Sat Oct 8 14:09:45 CEST 2016
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.
I was hoping to save the plots in a single file (perhaps PDF?). Do you have any additional tips for that?
Thanks
Jeremy
Sent from my iPhone
On Oct 8, 2016, at 2:10 AM, thomas collas <thomas.collas at gmail.com<mailto:thomas.collas at gmail.com>> wrote:
Dear Jeremy,
That should work if you change 3 things :
- the first problem is your stats object, which is a character vector, not a list of objects, you can't plot a character string.
- 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.
- 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.
After having created the two objects you want to plot, this code should work :
stats <- list(pamomf2i5q.w, pamwardomf2i5q.w)
par(mfrow=c(1,2))
for (i in stats) {
plot(i, stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")
}
Best,
thomas
2016-10-08 4:41 GMT+02:00 Reynolds, Jeremy E <reyno113 at purdue.edu<mailto:reyno113 at purdue.edu>>:
Dear TraMineR Users,
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:
plot(pamomf2i5q.w, stat=c("ASWw","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")
plot(pamwardomf2i5q.w, stat=c("ASWw","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")
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?
Thanks,
Jeremy
> stats <- c("pamomf2i5q.w", "pamwardomf2i5q.w")
> for (i in unique(stats)) {
+ plot(stats[i], stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")
+ }
<image001.png> Show Traceback
Rerun with Debug
Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In plot.window(...) : "stat" is not a graphical parameter
4: In plot.window(...) : "legendpos" is not a graphical parameter
5: In plot.window(...) : "norm" is not a graphical parameter
_______________________________________________
Traminer-users mailing list
Traminer-users at lists.r-forge.r-project.org<mailto:Traminer-users at lists.r-forge.r-project.org>
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users
_______________________________________________
Traminer-users mailing list
Traminer-users at lists.r-forge.r-project.org<mailto:Traminer-users at lists.r-forge.r-project.org>
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/traminer-users/attachments/20161008/a6843964/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 168 bytes
Desc: image001.png
URL: <http://lists.r-forge.r-project.org/pipermail/traminer-users/attachments/20161008/a6843964/attachment.png>
More information about the Traminer-users
mailing list