-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
98 lines (77 loc) · 2.98 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
dpi = 300,
message=FALSE,
warning=FALSE
)
```
[![Travis build status](https://travis-ci.org/italocegatta/fipe.svg?branch=master)](https://travis-ci.org/italocegatta/fipe)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/italocegatta/fipe?branch=master&svg=true)](https://ci.appveyor.com/project/italocegatta/fipe)
[![CRAN_Release_Badge](http://www.r-pkg.org/badges/version-ago/fipe)](https://CRAN.R-project.org/package=fipe)
[![CRAN_Download_Badge](http://cranlogs.r-pkg.org/badges/fipe)](https://CRAN.R-project.org/package=fipe)
# fipe
`fipe` is a R package to access [Fipe](https://veiculos.fipe.org.br)’s average purchase price of vehicles in the Brazilian national market. The prices are effectively used in purchase negotiations according to region, vehicle’s conservation, color, accessories or any other factor that might influence the demand and supply for a specific vehicle. The year of the vehicle refers to the model year, and the vehicles are not considered for professional or special use. The values are expressed in R$ (reais) for each month/year of reference.
## Installation
You can install the development version from github:
```{r eval=FALSE}
# install.packages('devtools')
devtools::install_github('italocegatta/fipe')
```
The stable version is availabe on [CRAN](https://CRAN.R-project.org)
```{r eval=FALSE}
install.packages("fipe")
```
## Example
The function `fipe_vehicle` provide access to historical data of brazilian cars price
```{r example}
library(fipe)
library(ggplot2)
library(dplyr)
bmw_x6 <- fipe_vehicle(
model = "x6 ",
make = "bmw",
year = c(0, 2017:2015),
date = seq.Date(as.Date("2013-01-01"), as.Date("2017-12-01"), by = "4 months")
)
bmw_x6
```
```{r plot_history, fig.width=8, fig.height=6}
bmw_x6 %>%
ggplot(aes(date, price, color = year, group = year)) +
geom_line(color = "grey30") +
geom_point(size = 3) +
facet_wrap(~model) +
labs(
x = "Referance date",
y = "Price (R$)",
color = "Year"
) +
scale_y_continuous(breaks = seq(0, 700000, 50000), labels = scales::number) +
scale_x_date(date_breaks = "1 year", date_labels = "%b/%y") +
scale_color_viridis_d() +
theme_bw() +
theme(legend.position = "top")
```
```{r plot_compare, fig.width=8, fig.height=6}
bmw_x6 %>%
filter(date == max(date)) %>%
mutate(model = reorder(model, price, max)) %>%
ggplot(aes(price, model)) +
geom_line(aes(group = model), color = "cadetblue4", size = 2) +
geom_point(size = 10, color = "cadetblue4") +
geom_text(aes(label = year), color = "white", size = 3) +
labs(
x = "Price (R$)",
y = "Model"
) +
scale_x_continuous(breaks = seq(0, 700000, 50000), labels = scales::number) +
theme_bw()
```