【问题标题】:How to fix legend's margins in base::plot?如何在 base::plot 中修复图例的边距?
【发布时间】:2021-11-23 00:18:15
【问题描述】:

我试图在question 中重现 akrun 的回答中的情节:

#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)

@akrun 有什么:

我有什么(传说有另一种形式和参数):

可能是什么问题?

【问题讨论】:

  • 无法重现您的问题;我正在使用类似于第一个的情节(Ubuntu 上的 R 4.1.0)
  • 我无法重现该问题。它仍然给我与第一个相同的输出。也许检查你的 options() 。我在 Mac 上使用 R 4.1.1
  • @desertnaut 我不知道,哪里有问题。但是当我复制(例如)Kabakoff 的书 Figure 3.10 An annotated comparison of Drug A and Drug B p.62 中的情节时 - 我遇到了同样的问题。
  • @manro 你能在控制台上输入par(),它会给出所有默认参数值。还要检查here
  • @akrun np - 我做到了。更正了问题

标签: r plot


【解决方案1】:

windows() 命令拯救了这一天;在弹出窗口中,图例看起来不错:

#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)

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2021-11-07
    • 1970-01-01
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    相关资源
    最近更新 更多