Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between autoplot function and plot function in R

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") 
like image 440
Jojo Joseph Avatar asked Dec 07 '25 04:12

Jojo Joseph


1 Answers

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

like image 61
Artem Avatar answered Dec 08 '25 19:12

Artem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!