How to add a point in normal distribution plot?

Hello everyone!

I created a normal distribution plot which actually works as I want. I tried to add a point but it fails to load it even if I got zero errors
typed this:

k<-0
z <- 25440

plot(x,y) + points(k,z,pch=19,col="blue",cex=5)

which gives me an output of

integer(0)

and my plot loaded without adding my desired point.

Does anyone have any idea how to handle it?
Thanks in advance

1 Like

Hello,

There are two things that need to be pointed out here:

  1. There is no need to use the + sign (that's for ggplot). You should just add the points() function below the plot as it will add to it automatically (that's what's generating the integer(0))
  2. In the base R plot, the canvas of the plot is decided when the plot function is used first based on the initial data (or specific arguments specified). All data added later that falls out of the initial canvas will not be visible as the canvas does not resize based on new data

Here is an example that works:

k<-5
z <- 0.5

plot(1:10, runif(10))
points(k,z,pch=19,col="blue",cex=5)

image

Here is one that won't show the blue dot as it falls outside the initial canvas

k<-5
z <- 5

plot(1:10, runif(10))
points(k,z,pch=19,col="blue",cex=5)

Most people use ggplot these days as it has a much more flexible, powerful and user-friendly style of coding. here are some resources if needed:
https://rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf

Hope this helps,
PJ

1 Like

Ok i understand. Thanks a lot for the cheatsheet. Its very very helpful material for R newbies!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.