0

some packages have special plot objects, so when you do plot(object) it produces one or several plots for this object.

An example is

data("cars")
m <- lm(dist~speed, data=cars)
plot(m)

which produces several plots to this linear model.

How can I get the code to these plots so I can manually reproduce them? In this case ?plot.lm has some more information, but that is not always the case.

To make it more clear, in this example the first plot is a residuals vs. fitted values plot, which I could get by plot(m$fitted.values, m$residuals). I found this by analysing str(m). In most cases this is not that obvious what the plot of an object does.

spore234
  • 3,550
  • 6
  • 50
  • 76
  • @jogo does not work. Also, there are package where `plot(object)` works but they have no `?plot.objecttype` help – spore234 Dec 21 '15 at 08:56
  • `plot.lm` is a internal function, i.e. the R-code is not available. So one have to go to the source code of R. (For other functions R-code is available, example `plot.ts`.) – jogo Dec 21 '15 at 09:01

2 Answers2

0

Use edit(plot) to know the structure of base-R function plot. To know the structure of your object use edit(objName).

Mithilesh Kumar
  • 256
  • 1
  • 3
  • 18
0

You can use the function getAnywhere to see the codes inside a S3 function e.g. plot.lm.

Reference

Community
  • 1
  • 1
pe-perry
  • 2,591
  • 2
  • 22
  • 33