How to bring life to your ggplots?


If you’re wondering how you can add a GIF layer to your ggplot to get something like the above image, one working example is given below [1].

library(here) # For making the script run without a wd
library(magrittr) # For piping the logo
ggplot(mpg, aes(displ, hwy, colour = class)) +

geom_point() +
ggtitle(“Cars”) +

ggsave(filename = paste0(here(“/”), last_plot()$labels$title, “.png”),
width = 5, height = 4, dpi = 200)
background <- image_read(paste0(here(“/”), “Cars.png”))

logo_raw <- image_read(“;)

frames <- lapply(logo_raw, function(frame) {
image_composite(background, frame, offset = “+100+50”)
animation <- image_animate(image_join(frames))
image_write(animation, “~/Cars_Travolta.gif”)

[1] Read more here: []

Posted in Programing | Tagged , , | Leave a comment

Stop Not Paying Original Content Creators on The Web, It’s Bad For Everyone


Imagine you have recently got a new idea that you have worked on for a while. You have made it mature enough that at this point you feel comfortable sharing it with the outside world. What you would do? How would you share it? Will you feel going through the time-consuming process of peer review journal publication? If relevant, will you consider publishing your work in a blogpost or social media platforms?  Do you feel motivated/rewarded enough to do so?

Classical Publication

If this is a technical, scientific novel idea that you have worked on hard for a long time, probably your best option is submitting your manuscript to a relevant peer review scientific journal for publication. If relevant, you may also fill and submit a patent application for your work.  For these classical sharing methods, here are the Pros:

  • Strict Copy Right protection
  • Peer reviewed
  • Targeted audience

and Cons:

  • Limited visibility
  • Slow rewarding process
  • Low rewarding (if not rewardless)

Besides all the above listed cons, for technical materials which have a very small size group of target audience your best option might be still the classical ways including publishing in technical peer review journals.

Modern Tools

But what if your idea/work is targeting a broader group of audience? The best example for this might be the article you are reading right now. This is a work that (1) I have thought about for a while (which is not a moody random thought passing through my mind and coming out of my mouth right away), (2) it is not too technical, (3) it is broad in scope, (4) it has the potential to make an immediate impact towards creating value.

To share such a work I wouldn’t submit this to a peer review journal, because of all the cons and irrelevant pros (for this case) listed above. Instead, I would think of using a more efficient way among modern publishing tools on the web such as blogging platforms and social media to share content. For these modern sharing methods, here are some of the advantages:

  • Fast process
  • Broad visibility
  • Copy Right protection to some extent

and here is the big disadvantage:

  • Rewarding doesn’t exist or is foolishly low, if it does [please see below to see why]

which not only hurts the OCCs, but also blocks the potential for absorbing more resources by other parties including consumers, hosting platforms, and enterprise. The image below displays the mechanism of how rewarding the OCCs leads to more value for everybody.


Web Marketplace for Original Content

Ecosystem and Inhabitants

Imagine the current ecosystem of original content marketplace on the public domain web. You may think of  at least four types of inhabitants in this ecosystem:

  1. Original Content Creators (OCC): who create original contents
  2. Content Customers: who consume the content including readers, watchers, and listeners.
  3. Hosting Platforms: which provide all the necessary skills and tools to share and communicate the contents
  4. Enterprise: which provides support to the Hosting Platforms for receiving advertisement services.

The Current Dynamics of The System

The animation below shows the overview of the current dynamics of transactions between these inhabitants in this ecosystem that I believe must change.


OCCs: The Only Party Not Getting Fed Fair By System

You should be able to notice why the above displayed dynamics does not provide a good deal for all the parties in this ecosystem, especially if you look at the following pyramid diagram. All the sections of the pyramid have at least one input and one output transaction except the OCCs which have no income in this marketplace. This is insane, if you think about it.


Inhabitant Contributions to The System

The following table summarizes the contribution of each party into the system and their take-out share. Although the OCCs might receive some credit during time eventually, this is far behind the true value they create by their work which is the driving force of the whole system i.e. the original content.


How It Should Work

By rewarding the OCCs, we not only make the OCC party happier, but also the other parties. As it was visually displayed above (Fig. 1) rewarding the content creators causes more value for the whole system.


Rewarding Original Content Ecosystem (ROCE)

Below animation visually summarizes the whole idea of how rewarding content creators empowers all: 1) content consumers (because, there will be more content and most probably better quality original contents), 2) Host Platform (because, there will be more visitors), and 3) Enterprise (because, their advertisements go farther to a larger audience which eventually causes more sell).


Challenges and Solutions

In Progress…

Posted in Efficient City | Tagged , , , , , | Leave a comment

Self-Driving Cars May Need To Know Why I Avoid Driving Behind Moving Trucks, But Choose to Stop Behind Them

Nope! This is not because of any safety issue that one may think of initially, but only because I would like to spend less time behind traffic lights during my daily commute in St. Louis. This can buy even more time for people in New York City and Los Angeles, I believe.

This note includes a problem and the solution. I can’t go to the solution without describing the problem. Therefore, let me describe the problem and the conditions first.

The Question

Imagine a one-way road with one line of cars all going forward towards a traffic light. Let’s look at this situation in four different times:


  1. t=t0 in which the light is green and cars are moving. This is in the past time before your car arrives.
  2. t=t1 in which the light has turned to red already and your car reaches to the tail of the traffic jam.
  3. t=t2 in which your car comes to stop right behind the front car AND at exactly the same moment the light turns green in the very front of the line.
  4. t=t3 in which the light is still green and the car in front of you has just started to move and reached in distance “d” from you. Now it’s time for you to move!

Now, the question is: will you pass this green light before it turns red again?

For simplicity, let’s make a few clear assumptions.

  • Each car only sees the front car and reacts only based on this piece of information.
  • All cars have the same length [= L].
  • When a car moves, it always keeps the same distance from the car in its front [= d] AND always moves with a constant speed [= V0] (no acceleration).
  • A car moves if and only if the car in its front is moving in exactly the distance of “d”.
  • When cars stop, they stop right behind the next car in their front.
  • A car comes to stop if and only if the car in its front is in stop (or it sees the red light).

The Answer

If the traffic light is fair in time (i.e. it stays red the same amount of time as in green), in the given assumptions, you can never make this green light in this round! The light will turn red before you pass it.

In the given conditions, you have to always wait for the next green light. This is independent of the length of the vehicles in front of you. However, when you are moving, you’d better drive in a lane in which the ratio of the length of the vehicles to the distance between the vehicles (L/d) is lower. The speed of traffic jam packing up for lanes in which there are larger vehicles is higher. However, it is better standing behind a standing line of large vehicles than small ones with the same length of line, if you have a choice. You can find out why these are true by reading the rest of this note.


The final quantitative result that I obtained with respect to the above described conditions is as following. You can never pass this green light this round if and only if:


where “tGreen” and “tRed” are the green time and red time, respectively, “L” is the average length of the vehicles in the line, and “d” is the average distance between moving vehicles.

If you are curious how you can derive this, here is my step-by-step approach.

  1. Let’s define “X” as the length of the traffic jam at the moment your car arrives.
  2. Let’s define “X_prime” as the distance you can drive from the moment you are permitted, i.e. the moment in which the front car starts to move and reaches the distance “d” from you.
  3. If “X_prime” turns to be bigger than “X”, you will pass the green light; otherwise, you won’t!

Here are the values of “X” and “X_prime” in terms of other variables in this problem:


in which “LV0/d” is the speed of traffic jam! In other words, if we want to calculate the length of the line of cars from the moment the light goes red until our car arrives and stops (in which the light turns green again), we have to think with what speed the traffic jam grows. Well, the answer is very simple if you think about it. Each time one car stops behind another car, the length of the line grows by the length of that car. Therefore, the speed of traffic jam growth is equal to “L” devided by the time it takes for one stop [d/V0] which is exactly what you see in the equation above. This also describes why bigger vehicles make longer traffic jams and therefore you should reconsider driving behind moving trucks.


where has two time terms. The first term represents the whole green cycle time. The second term, however, shows the time wasted since the light turned green until you can actually move. This later time term is also very easy to quantify if you think about it. There is a delay time for each car to be able to move. This delay for each car is equal to the time it takes for the front car to travel distance “d” which is “d/V0”. Let’s assume there are “n” cars in front of us. The total wasted time will be equal to “n” times “d/V0”. But we can estimate how many cars are in front of us in terms of “X” (the length of the line), “n = X/L”. This justifies the second term inside the parentheses.

Assume the length of the traffic line is fixed (X). In this situation, according to the above relation, there will be less wasted time if “L” is larger. That’s why you should consider stopping behind trucks in a traffic jam.

“X_prime” defined above is the distance you can go forward before the light turns red! Bigger “X_prime”, bigger gain! It is interesting to see how this value is related to the other parameters. If we simply substitute “X” in the relation for “X_prime”, we obtain:


which speaks for itself. In this given simplified situation, if the red time and green time are equal, the light always turns red even before you get a chance to move. However, it doesn’t mean that you don’t move forward. You will, but the traffic light is red already. This relation also clearly shows “X_prime” is independent of the lenght of the vehicles and the distance between them. You will end up being in longer lines by driving behind large vehicles though. That’s the only difference.

As we mentioned earlier above in the third bullet, the idea is that the last car which comes to stop at the tail of the traffic jam (and don’t forget this is right at the moment the light turns green at the front of the line) can catch the same green light if and only if: “X_prime > X”. This describes the main equation in this note.

For completeness, it needs to be mentioned that this solution may or may not be a good estimate for when other parameters come to play, for example the acceleration of the cars and variable “d” and variable reaction times of the cars, to name a few. I do believe, however, that the results in this note is enough to convince you not to drive behind large vehicles in unknown roads and consider stopping behind them when you have a choice.

I also think this is a piece of information that self-driving cars should consider in their decision making. The following flowchart shows how a draft of what a self-driving car decision making algorithm should consider for changing lanes:


All the above discussion given, at the end of the day, the story is quite simple if you think about it: the traffic status change signal (stopping-signal or moving-signal) travels along a lane with a velocity equal to the length of the individual vehicle, for which the traffic status signal is passing through it at this moment, divided by the reaction time of that vehicle. This describes the logic behind the above flowchart.

Posted in Efficient City, Physics | Tagged , , , , , , , , | Leave a comment

Hafez Nazeri – Existence Life


I received a request at simbi to translate the lyrics of the above song from Persian to English. Following is what I sent back to that person as the result. It was a nice experience.

نامدگان و رفتگان ازدو کرانه ی زمان
سوی تو می دوند هان ای تو همیشه درمیان

Hey you, who have always been around! All including those who have already passed away and those who have not yet come to existence (not born yet) are both rushing to you from two horizons of time [i.e. past and future].

پیش وجودت از عدم زنده و مرده را چه غم ؟
کز نفس تو دم به دم می شنویم بوی جان

With your existence, what would cause the living and the dead to be worried about inexistence at all?
We smell the scent of life from your breath every moment…

پیش تو جامه در برم نعره زند که بر درم
آمدمت که بنگرم گریه نمی دهد امان

In your presence, the clothes on my body yell that “tear me!”…
I came to gaze at you, but tears don’t let me…

آه که می زند برون ، از سر و سینه موج خون
من چه کنم که از درون دست تو می کشد کمان

Alas, the wave of blood is jumping out of the head and the chest…
What can I do? Since this is because a bow is pulled back by your own hands inside me…

Poet: Hooshang Ebtehaj

Posted in Links | Tagged , , , , | 2 Comments

An Interview


Video | Posted on by | Tagged , , | Leave a comment