Note that there are some explanatory texts on larger screens.

plurals
  1. POPlotting in a consistent manner across platforms
    primarykey
    data
    text
    <p>I decided it was important for R users to be able to play hangman and made an R hangman game. The problem is I don't do many plots for general release and so I don't know how to provide the user with a plot that works independent of platform or gui.</p> <p>Here's where you can download the complete package that contains large word bank:</p> <pre><code>library(devtools); install_github("hangman", "trinker") </code></pre> <p>The function that plots looks like this (I made the word bank go away for reproducibility):</p> <pre><code>hangman &lt;- function() { #x1 &lt;- DICTIONARY[sample(1:nrow(DICTIONARY), 1), 1] x1 &lt;- "trapped" x &lt;- unlist(strsplit(x1, NULL)) len &lt;- length(x) x2 &lt;- rep("_", len) chance &lt;- 0 win1 &lt;- 0 win &lt;- win1/len wrong &lt;- character() right &lt;- character() print(x2, quote = FALSE) hang.plot &lt;- function(){ #plotting function plot.new() mtext("HANGMAN", col = "blue", cex=2) mtext(paste(x2, collapse = " "), side = 1, cex=1.5) mtext("wrong", side = 3, cex=1.5, adj = 0, padj = 5, col = "red") text(.015, .8, paste(wrong, collapse = "\n"), offset=.3, cex=1.5, adj=c(0,1)) mtext("correct", side = 3, cex=1.5, adj = 1, padj = 5, col = "red") text(.96, .8, paste(right, collapse = "\n"), offset=.3, cex=1.5, adj=c(0,1)) segments(.365, .77, .365, .83, lwd=2) segments(.365, .83, .625, .83, lwd=2) segments(.625, .83, .625, .25, lwd=2) segments(.57, .25, .675, .25, lwd=2) parts &lt;- seq_len(length(wrong)) if (identical(wrong, character(0))) { parts &lt;- 0 } if (1 %in% parts) { mtext("O", side = 1, cex=4, adj = .365, padj = -7.2) mtext("o o", side = 1, cex=1, adj = .3725, padj = -28.2) mtext("&lt;", side = 1, cex=1, adj = .373, padj = -27.6) mtext("__", side = 1, cex=1, adj = .373, padj = -27.2) } if (2 %in% parts) { mtext("I", side = 1, cex=4, adj = .375, padj = -6.25) mtext("I", side = 1, cex=4, adj = .375, padj = -5.5) mtext("I", side = 1, cex=4, adj = .375, padj = -4.75) } if (3 %in% parts) { segments(.37, .57, .45, .63, lwd=7) } if (4 %in% parts) { segments(.37, .57, .29, .63, lwd=7) } if (5 %in% parts) { segments(.37, .426, .43, .3, lwd=7) mtext("__", side = 1, cex = 1, adj = .373, padj = -27.2, col = "white") mtext("O", side = 1, cex = 1.25, adj = .373, padj = -21.5, col="red") } if (6 %in% parts) { segments(.37, .426, .31, .3, lwd = 7) mtext("o o", side = 1, cex = 1, adj = .3725, padj = -28.2, col="white") mtext("x x", side = 1, cex=1, adj = .3725, padj = -28.2) mtext("You Lose", side = 1, cex=8, padj = -3, col = "darkgreen") mtext(paste(x2, collapse = " "), side = 1, cex=1.6, col="white") mtext(paste(x2, collapse = " "), side = 1, cex=1.5, col="white") mtext(paste(x2, collapse = " "), side = 1, adj = .51, cex=1.6, col="white") mtext(paste(x, collapse = " "), side = 1, cex=1.5) } if (win1 == len) { mtext("WINNER!", side = 1, cex=8, padj = -3, col = "green") mtext("WINNER!", side = 1, cex=8, adj = .1, padj = -3.1, col = "darkgreen") } } #end of hang.plot guess &lt;- function(){#start of guess function cat("\n","Choose a letter:","\n") y &lt;- scan(n=1,what = character(0),quiet=T) if (y %in% c(right, wrong)) { stop(paste0("You've already guessed ", y)) } if (!y %in% letters) { stop(paste0(y, " is not a letter")) } if (y %in% x) { right &lt;&lt;- c(right, y) win1 &lt;&lt;- sum(win1, sum(x %in% y)) win &lt;&lt;- win1/len message(paste0("Correct!","\n")) } else { wrong &lt;&lt;- c(wrong, y) chance &lt;&lt;- length(wrong) message(paste0("The word does not contain ", y, "\n")) } x2[x %in% right] &lt;&lt;- x[x %in% right] print(x2, quote = FALSE) hang.plot() }#end of guess function hang.plot() while(all(win1 != len &amp; chance &lt; 6)){ try(guess()) } if (win == 1) { outcome &lt;- "\nCongratulations! You Win!\n" } else { outcome &lt;- paste("\nSorry. You loose. The word is:", x1, "\n") } cat(outcome) } </code></pre> <p>This looks great on RGUI (in windows) where I created it but the plot is misconfigured in RStudio. How can I make the code plot everything in a way that lines up/looks good independent of gui/platform (my friend bryangoodrich suggested grid as a possibility)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload