I saw that even by writing separate commands, we can combine two different types of plots in R. For example, if a histogram has been created in R where the histogram plots points representing the frequency of the items, we can connect these dots by calling a line() function. Now, these two plots are separate commands.
How does this work in R? When can it combine plots and what is actually supported here?
Thanks
Abhishek S
Once you have drawn a plot, you can usually just draw on top of it with any other plotting functions that do not call for a new plot (i.e. that clear the plot window and reset the coordinate system). There are some caveats of course.
One important one is that the plot function needs to preserve the correct coordinate system otherwise the mapping from the data used to add a line and the plot will be corrupted – they won’t line up.
Another consideration is that what you propose is only possible for a single “panel” plot or for the last panel drawn in a multi panel plot. If a multipanel plot has been drawn usually you will find that the plotting function is a good citizen and resets the coordinate space/plot window to a single panel. That will break links between the data and the plot that will be difficult to recreate.