3

What is the difference between these two functions

plot(AP,xlab="Date", ylab = "Passenger numbers (1000's)",main="Air Passenger numbers from 1949 to 1961")

autoplot(AP) + labs(x ="Date", y = "Passenger numbers (1000's)", title="Air Passengers from 1949 to 1961") 
Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Jojo Joseph
  • 1,493
  • 1
  • 15
  • 12
  • 1
    `plot` is from base R and `autoplot` is part of the `ggplot2` package. These are two different plotting systems. See for example here for an explanation: https://flowingdata.com/2016/03/22/comparing-ggplot2-and-r-base-graphics/ – symbolrush Sep 19 '18 at 05:50
  • 1
    What does the difference look like? – Spacedman Sep 19 '18 at 07:31

1 Answers1

1

From the point of view of graphical data representation there is not much difference between graphics::plot and ggplot2::autoplot + ggfortify package for time-series plotting. The difference will be obvious if you will start to plot more complex plot (facetting, multiplot, grouping etc.). As for your question please see below:

graphics::plot:

data(AirPassengers)
AP <- AirPassengers
plot(AP, xlab="Date", ylab = "Passenger numbers (1000's)", main = "Air Passenger data, base")

base

ggplot2::autoplot:

library(ggplot2)
library(ggfortify)
data(AirPassengers)
AP <- AirPassengers

autoplot(AP) + 
  labs(x ="Date", y = "Passenger numbers (1000's)", title = "Air Passengers from, ggplot2")

enter image description here

Artem
  • 3,304
  • 3
  • 18
  • 41