I want to plot two functions in different colors and point styles with a corresponding legend, in plain R.

I have several questions:

  1. I am using pch=21 and pch=22. My understanding is that they are "filled" symbols. They do appear filled as expected in the legend, but they appear hollow on the graph itself. What's wrong?

  2. Can I get more space between the points without specifying a grid manually? maybe by selecting the number of points to be printed?

  3. Feel free to add any kind of advice you'd like. I'm very new to R. In particular, is there a better way to plot two functions? e.g. by defining vectors of functions? and wouldn't there be a way for the legend to be automagically generated without having to specify colors and shapes, in plain R?

Here's my code:

par(new=TRUE)
p1 <- plot(function(x){ x^(2)/2 }
       , 0, 100
       , xlab = "x"
       , ylab = "y"
       , ylim = c(0,5000)
       , las = 1
       , type = "p"
       , cex = 0.8
       , pch = 21
       , col = "red"
)
par(new=TRUE)
p2 <- plot(function(x){ (1-x^(2))/2 }
       , 0, 100
       , xlab = ""
       , ylab = ""
       , axes = FALSE
       , type = "p"
       , cex = 0.8
       , pch = 22
       , col = "blue"
)
par(new=TRUE)
l <- legend( "topleft"
         , inset = c(0,0.4) 
         , cex = 1.5
         , bty = "n"
         , legend = c("A", "B")
         , text.col = c("red", "blue")
         , pt.bg = c("red","blue")
         , pch = c(21,22)
)

After various explorations, I opted to use the par(new=TRUE) "trick" to superimpose the two functions (rather than, say, using matplot or a combination of plot and points or layout). Was that a bad move to begin with? (Edit: yes, very bad, see below) +1 if you don't ask me to read the manual ;-)

enter image description h</div>
                    
                    <div class= r plot legend

Edit
Report