I have made this page to simply produce a sample forceast plot. Let’s say we have estimated revenues in billions of dollars of three different classes of MEMS devices {pressure sensors, accelerometers, and digital compass}. And the goal is to produce a forecast chart of the entire industry which sums up all the three classes of devices, and to be able to simultaneously understand the proportions of contribution of each class of device. This requires a barplot.

Fortunately, it is very easy to do this with R. It requires a simple matrix to be passed as an argument to the barplot() function.

In the following lines, let’s prepare a mock dataset of the revenues in billions of USD.

year <- c(2014:2020)
pressure_sensors <- c(1, 1.1, 1.3, 1.6, 1.8, 2, 3)
acceleros <- c(2, 2.5, 3, 6, 8, 8, 9)
digital_compass <- c(0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1)

Once we have a raw data of vectors like this, we just make a matrix by combining these vectors. The code is as follows.

matrix <- rbind(pressure_sensors, acceleros, digital_compass)
colnames(matrix) <- year

So, the matrix actually looks like this:

##                  2014 2015 2016 2017 2018 2019 2020
## pressure_sensors  1.0  1.1  1.3  1.6  1.8    2  3.0
## acceleros         2.0  2.5  3.0  6.0  8.0    8  9.0
## digital_compass   0.5  0.6  0.7  0.8  0.9    1  1.1

Now, we have constructed the data in a form we like that’s ready for plotting. It’s a very simple function in R. Goes like this:

barplot(matrix, col = c("blue", "red", "green"), legend.text = rownames(matrix), 
        args.legend = list(x="topleft"), xlab = "Year", ylab = "Revenue in billions of $s",
        main = "Revenue forceast for different classes of MEMS devices")