Please help me to add a legend to this plot: - normal, -examined, like on a picture above.
Second I would like to recreate this base R plot in ggplot, how do I do it ?
regards,
When I tried to do it on a single plot I kept receiving errors. How to superimpose these plots or melt them to one plot ? In other words how to draw two eCDFs (actually one eCDF and one CDF) on a single plot ?
Any help will be greatly appreciated.
I think of ggplot as saying get a piece of graph paper. So you asked for two pieces of graph paper so you drew two plots.
ggplot() +
geom_line() + #draw a line on the graph
geom_line() # draw another line on the same graph.
So in your case;
ggplot ()+
stat_ecdf () +
stat_function()
I don't quite understand the maths etc of what you are doing, so I can't comment on the actual plot but if x2 needs to be in an aes for stat_function put the aes inside stat_function(aes(x2))
The base legend. A lot of people might simply use a small line and text. Have you tried using legend()?
Why are you trying to draw the same thing in base and in ggplot?
This shows that 22 rows of data can't be plotted. Since you are learning both you are presumably trying to figure out which is best. Did base R tell you it couldn't plot 22 values? Thought not! That's not because it could (they are non-finite) - it just didn't tell you. OK. Fixes ? 1. Look at the data and understand why. I suspect it's to do with points at zero. In which was filtering those off would help avoid the error. Or you say it's just a warning and carry on.
OK. Legends. Ggplot can't make up it's mind what to call them. Legends and guides. And Ggplot puts them outside the plot by default. Let's start with that.