Drawing multiple routes on a roadmap


The R package Leaflet can be used to draw beautiful maps. Polygon shapes can be added to draw lines and borders. By combining these functionalities with GPS data, you can easily draw roadmaps of your recent whereabouts (or tag your cat with a GPS tracker and see where he likes to hang out over the weekends). Besides detailed GPS data of your route, you can also use simple start-destination combinations and let a route planner API come up with the exact GPS coordinates of the route. A taxi company for example, can draw maps of its customer exposure to the city or track hotspots that are often visited by drivers. A delivery service can identify regions where they have little presence and where they perhaps should invest in customer awareness.

In R, a list of 1000 cities was formed by selecting postal codes with replacement by distance from a random subset of Western European cities. All starting points where set to be in Venlo or Rotterdam, the Netherlands. Using ggmap, cities were translated into GPS coordinates and routes were calculated. These routes were then plotted on a CartoDB map using the Leaflet package.


These maps can be produced quite fast, and they are easily integrated into interactive applications by using the Shiny package. They could be used to study traffic flow or for marketing purposes.

How much value does your car lose each year?


When you buy a car, there are many things you may take into account. Mileage, model year, colour, reliability, safety, just to name a few. You may also consider what this car will be worth if you sell it in a year or two. This depreciation in car value is something we often have to guess. If the car is relatively new, the price depreciation can be as high as 25% in the first year. In general, a car that is rare, exceptionally good, or just part of some cult following will keep its value for much longer than a common car. This is a list of cars that drop most in price, and this is a list of cars that drop least. Getting accurate calculated data for your specific car is hard to find however.

Car prices do not drop in a linear fashion. The first minute after having bought a new car, its value will drop almost 10% according to this infographic. After 1 year its value will have dropped by 20%, and after 5 years about 60%. It also depends highly on local demand. Secondhand car prices in Germany are cheaper than those in the Netherlands for example, even after adjusting for taxes. In Belgium and France, French cars are in much higher demand than in Germany.

In order to reflect local demand, local car prices can be used to calculate price depreciation. The internet contains a lot of information on secondhand prices which are sorted by nation or even by postal code. In R, a webscraper can be used to collect information on secondhand car prices. Information related to mileage, model, transmission, engine type, fuel and model year can be used in non-linear regression models to predict car prices the next year. Each car model has different parameters and some parameters are adjusted to obtain a better range of reliable results.


Using R Shiny, an interactive application can be developed for a selected set of car models. The app calculates price depreciation based on the car model and properties chosen, such as fuel, transmission and mileage. It shows the current price, next year's expected price and the total price depreciation. In the second row it shows depreciation per year, per 10.000 km, and per 50.000 km specifically (while keeping other factors constant). The first plot shows the relation between model year and price for all related models. The second plot shows the relation between mileage and price.