Geo-Spatial reporting with R

Many times we need to plot geo-spatial data in analytics. Information like sales per region, income distribution makes more sense when they are plotted on a map. We can do this quite easily in

R. Let us see it in action.

First of we need data about the map. There are many libraries from where we can download this data

for our personal use. Here we will use data from http://gadm.org/  Here there are data at different levels of details available for most countries. Let us use data for India. To load this downloaded data into R, first open R in R-Commander and change your working directory to where you saved the file


setwd(“/home/soumyanath/Downloads/R_Maps”)
and then read the data into a variable with

ind1 <- readRDS(“IND_adm1.rds”)

Let us check what kind of data has been loaded with

class(ind1)

It will show

[1] “SpatialPolygonsDataFrame”

attr(,”package”)

[1] “sp”

As it is SpatialPolygon, let us load library(sp)

library(sp, pos=4)

library(methods, pos=4)

Now, the question is, how do we see this data? There is a function to plot spatial data, we use that

spplot(ind1, “NAME_1″, scales=list(draw=T), colorkey=F, main=”India”)

will show a map. Actually I do not like it, it shows a truncated view of Kashmir, but then we are

using data from an USA repository and I have no means to influence them. We shall revisit this part at a later stage on how to correct the maps, but for now, let us make use of what we have. To manipulate data we need to know properties of the data that we have. We can look into the loaded data with names function. It shows:

> names(ind1)

 [1] “OBJECTID”  “ID_0”      “ISO”       “NAME_0”    “ID_1”      “NAME_1”    “HASC_1”    “CCN_1”     “CCA_1”    

[10] “TYPE_1”    “ENGTYPE_1” “NL_NAME_1” “VARNAME_1”


We can also check property of the data by using

summary(ind1)

This will show various properties of data loaded. Right now we are interested in knowing ID for the states so that we can use it to color the maps with our data. We can user print(ind1) to view complete data, but in this case it will be a huge print. In this example we will use state ID “HASC_1” to plot our data. We can see the values with:

print(ind1$HASC_1)

Right now we do not have any data so we populate a excel sheet and fill data with state ID, fill some sales data and assign a color value based on sales amount. In reality we will probably use a data base to get this data. We save data into csv format and read it in R by:

pdata = read.csv(“filename”)

confirm data has been read correctly

We add a new property color.data into the dataframe ind1 based on color values taken from csv file

ind1$color.data =pdata[pdata[1]==ind1$HASC_1,3]

Now we plot the map with these color. The command is

spplot(ind1,”NAME_1″,  col.regions=ind1$color.data, colorkey=T, main=”Indian States”)

We have the result here

Same concept can be extended to district level for more granular analysis.

In our next blog, we shall see how to link this map projection with database to get real time analysis

Advertisements

Flower Recycling Options

Today in the news feed I saw a news that I thought I shall dwell a bit. The news was about a new venture setup by two friends Ankit Agrawal and Karan Rastogi. They are from a place that is pretty close to my heart — Kanpur.  The city is one of the typical polluted industrial city that has grownup organically without much planning. But what these guys did is commendable.

These friends realized that our religious minded people do not like to dump flowers in garbage. They would dispose these flowers in river. The flowers, approximately 80, 00,000 tons  that gets dumped in rivers cause enormous pollution. They have setup a venture to collect these flowers and use vermi-culture to convert it into good organic fertilizer.

It is a novel idea, but I would say it is also a waste of sorts. Flower has many things that we value – smell and color are two most visible thing in flower. Dried and grounded flower powder is often used as gulal that we use during holi. Essential oil from flower can be extracted by many different methods, like:

  • Enfleurage
  • Expressed Oils
  • Steam Distillation
  • Solvent Extraction
  • Fractional Distillation and Percolation
  • Carbon Dioxide Extraction
  • Phytonic Process

More details about it can be found in Nan Martin’s blog.

As we have a huge stock of flower, extracting this oil could lead to substantial increase in our GDP. After extracting the oil we may use the flower for making organic dye, that can be used in our textile and other cottage industries, part of it can also be used to make organic gulal. Only after we have actually extracted the usable parts, we should feed the rest to worms. Worms do not need the perfume and color, we do.

Recycling is good but making full use of the potential is better.

Winners are different…

A winner is NOT one who NEVER FAILS……but one who NEVER QUITS!!!”
Need proof? Read on…

Officials rejected a candidate for a news broadcasters post since his voice
was not fit for a news broadcaster.
He was also told that with his obnoxiously long name,
he would never be famous. He is

>>>>>>>>>
>>>>>>>>>

Amitabh Bachchan. (Hindi Films Super Star )
——————————————-

In 1962, four nervous young musicians played their first record audition for
the executives of the Decca Recording Company.

The executives were not impressed. While turning down this group of
musicians,
one executive said, “We don’t like their sound. Groups of guitars are
on the way out.”
The group was called
The Beatles.
——————————————–
In 1944, Emmeline Snively, director of the Blue Book Modeling Agency told
modeling hopeful Norma Jean Baker,
“You’d better learn secretarial work or else get married”.
She went on and became
Marilyn Monroe.
———————————————-
In 1954, Jimmy Denny, manager of the Grand Ole Opry,fired a singer after one
performance. He told him,
“You ain’t goin’ nowhere son. You ought to go back to drivin’ a truck”.
He went on to become
Elvis Presley.
— – ——————————————–
A small boy–the fifth amongst seven siblings of a poor father,
was selling newspapers in a small village to earn his living.
He was not exceptionally smart at school but was fascinated by
religion and rockets.

The rockets he designed failed multiple times
and he was made a butt of ridicule.
He is the person to have scripted the Space Odyssey of India
single-handedly. He is
Dr. A.P.J. Abdul Kalam.President of India.
——————————————-
When
Alexander Graham Bell invented the telephone in 1876,
it did not ring off the hook with calls from potential backers.
After making a demonstration call, President Rutherford Hayes said,
“That\’s an amazing invention, but who would ever want to see one of them?”
——————————————-
When
Thomas Edison invented the light bulb,
he tried over 2000 experiments before he got it to work.
A young reporter asked him how it felt to fail so many times.
He said, “I never failed once. I invented the light bulb.
It just happened to be a 2000-step process”.
——————————————-
In the 1940s, another young inventor named
Chester Carlson
took his idea to 20 corporations, including some of the biggest in
the country.
They all turned him down. In 1947, after 7 long years of rejections,
he finally got a tiny company in Rochester, NY, the Haloid Company,
to purchase the rights to his invention–an electrostatic
paper-copying process.
Haloid became
Xerox Corporation.
——————————————

A young graduate preparing for his public service examination failed in Bengali language test by his professors. They told him, his language is archaic and has many mistake.

He was Bankim Chandra Chatterjee. One of the most successful Bengali writer, creator of the National Song of India – Vande Mataram.
—————————————————————————
An young student took up research on a subject which nobody thought to be important. The work was thought so useless that She was asked to shift her work to a damp basement.

Well this Student got two Nobel Prize. In case you are still wondering – her name is Marie Curie.

She received many honorary science, medicine and law degrees and honorary memberships of learned societies throughout the world. Together with her husband, she was awarded half of the Nobel Prize for Physics in 1903, for their study into the spontaneous radiation discovered by Becquerel, who was awarded the other half of the Prize. In 1911 she received a second Nobel Prize, this time in Chemistry, in recognition of her work in radioactivity. She also received, jointly with her husband, the Davy Medal of the Royal Society in 1903 and, in 1921, President Harding of the United States, on behalf of the women of America, presented her with one gram of radium in recognition of her service to science. But when She did her research, it was thought to be insignificant work.
——————————————————————————

Don’t say you’re not important! It simply isn’t true, Life unfolds as we travel through time.
Enjoy the life as it emerges, It will stand throughout the ages, Savor each chapter as you go, Taking time to turn the pages.

You can make a difference, You see, it’s up to you!

Was it a dream?

It was a difficult night. My last night at TMTC on a training session. It was unusually hot night for Pune weather. I was not able to sleep.

Those of you who are not familiar with TMTC, let me tell about it. TMTC is a training center for Tata employees. Located adjacent to Pune railway station in a sprawling campus. The main building where classes are held is an old mansion of grand victorian design. The training sessions are fully residential. There are few guest rooms in the campus. After office hours the huge area with old trees becomes more of a tourist spot than a college. Concieving and maintaing such a place in heart of the city calls for a finely cultured taste.

This was the last day, many participants had left in the evening itself. My train was in early morning. I had noting to do so went to bed a bit early. Around eleven o’clock there was large bang in the ac and it went off with a smoke. Along with it went the power supply for the room. I came out of my room, but there is not a soul to be found at that hour so I went back to my bed.

I slept for hardly one hour, there was a sharp knock on my door. I opened the door thinking some electrician has come to repair the air conditioner. But there was a lady standing. She gestured me to follow her. I was dazed from sudden awaking, I stopped to ask her some thing. The lady turned back as if reading my mind. Put her finger on her lips, gesturing me not to speak and urged me to come with her. I was too stunned to think and followed her. She was wearing a flowing white dress. It was a full moon night, so there was plenty of light but there was a haze. The fog was very dense slightly above the ground. Top of the trees were completely hidden in the mist. At a distance some owl was hooting.

We walked for quite some thing, away from the guest rooms, crossing a lawn and the main building we went into a garden. There was a fountain flowing beside a rose bush. Just beside it there was a marble bench. The lady gestured me sit there and asked me to wait. Then just vanished.

I mean, here she was there in front of me, but then I could not see her any more. The fog was thickening. I waited and waited then finally got up to search for here. Suddenly she came out from the main building with a dazzling smile on her face. She asked me to follow her again, but this time I lost my cool. I asked her what is this about. She said nothing and gestured me impatiently to come after her.

This was getting too much for my nerves. I rushed and tried to reach for her hand. Then suddenly I fell down. I was falling into nowhere….

“Sir, Sir! Sir!!!” the chowkidar was shaking me. “You leave at once for the station. Your car has come” He said. “I was searching for you every where, it is already too late”. I saw my watch, the train is to leave Pune within next ten minutes. There was no time to think. I grabbed my baggage and jumped into the cab. The chowkidar was telling “It is not good to come near the main building….”

Later when I was settled in the train, it was passing Lonavala. In the cloud I could see two eyes as if waiting for me, or was it a trick played on my sleepy eyes I am yet to decide.

Laminated Newspaper jacket: Cheap thermowear – to protect poor from cold


More than 200 dead as South Asia gripped by icy weather.

I read this some 20 yrs ago,a cheap soluion to keep people warm. Thought of sharing over the net so that the idea may be used by some body to help the poor.

Essentially you put two piece of news paper sandwitched between two sheets of pvc. This can then be stitched or pasted to make airtight joints.

Price of the items is almost nothigs but this thing is very warm; better than many costly woolen garments. Mind you, it is not recommended for continious use. One may wear it over another clothing.