0

I tried to reproduce the plot from akrun's answer in this question:

#create data
a = abs(rnorm(100,10,10))
b = abs(rnorm(100,10,10))
i = 1
c = data.frame(a,b,i)
c$col = as.factor(ifelse(c$b>10,"red", "blue"))

#making plot
plot(c$a, type = "h", col = c$col, main = "plot_1, i = 1", 
      ylim = c(0, 100))
legend(1, 95, legend=c("Sampled", "Not Sampled"),
      col=c("red", "black"), lty=1:2, cex=0.8)

What had @akrun: enter image description here

What have I (legend has another form and parameters):

enter image description here

What can be the problem?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
manro
  • 3,529
  • 2
  • 9
  • 22
  • 1
    Cannot reproduce your issue; I am taking a plot similar to the first one (R 4.1.0 on Ubuntu) – desertnaut Oct 17 '21 at 21:41
  • I couldn't reproduce the issue. It is still giving me the same output as the first one. Maybe check your `options()` . I am using R 4.1.1 on a mac – akrun Oct 17 '21 at 21:42
  • @desertnaut i don't know, where is a problem. But when i reproduce (f.e.) an plot from Kabakoff's book ```Figure 3.10 An annotated comparison of Drug A and Drug B``` p.62 - i have the same problem. – manro Oct 17 '21 at 21:47
  • @akrun what i should check? i have 4.1.0. on Windows – manro Oct 17 '21 at 21:48
  • 1
    @manro Can you type in `par()` on your console and it gives all the default parameter values. Also check [here](https://stackoverflow.com/questions/9292563/reset-the-graphical-parameters-back-to-default-values-without-use-of-dev-off) – akrun Oct 17 '21 at 21:54
  • 1
    @akrun np - i do it. corrected the question – manro Oct 17 '21 at 22:16
  • Main reason is I can't reopen somebody closed question because of a meta post – akrun Oct 17 '21 at 22:18
  • This is reopened now. I rolled back the answer section because your question should remain strictly a question. It's still available from the [revision history](https://stackoverflow.com/posts/69404370/revisions) if you want to post it as an answer instead. – tripleee Oct 19 '21 at 04:39

1 Answers1

0

The windows() command saves the day; in the pop-out window, the legend looks OK:

#create data
a = abs(rnorm(100,10,10))
b = abs(rnorm(100,10,10))
i = 1
c = data.frame(a,b,i)
c$col = as.factor(ifelse(c$b>10,"red", "blue"))

windows() #!!!!HERE

#making plot
plot(c$a, type = "h", col = c$col, main = "plot_1, i = 1", 
   ylim = c(0, 100))
legend(1, 95, legend=c("Sampled", "Not Sampled"),
   col=c("red", "black"), lty=1:2, cex=0.8)

enter image description here

desertnaut
  • 57,590
  • 26
  • 140
  • 166
manro
  • 3,529
  • 2
  • 9
  • 22