图例使用磅“#”加pch 15

时间:2019-04-20 05:33:34

标签: r

让我留下了简单的图例以打印适当的符号,第一个必须是正方形,即pch 15,第二个需要为“#”

[平方] y = x ^ 2 [标签] y = 1-x ^ 2

File "/home/username/anaconda3/lib/python3.6/ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/home/username/anaconda3/lib/python3.6/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 0

    ^
SyntaxError: unexpected EOF while parsing

现在,正在发生的情况是图例看到1,然后是5,它应该是正方形和井号,我在做什么错了?

1 个答案:

答案 0 :(得分:0)

一种方法是将legend重复两次,同时将其中一个更改为缺失值(NA

plot(1, 1)
sapply(list(c(15, NA), c(NA, "#")), function(x) 
   legend("topright", legend = c("y=x^2", "y=1-x^2"),
             col=c("red", "blue"),cex=1, pch = x))

enter image description here