How to assign labels to observations in a scatter plot?

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

How to assign labels to observations in a scatter plot?

Postby Liu » Tue Sep 13, 2011 8:40 am

Hi,
I'm trying to create a scatter plot graph. The data is like below: (country is an alpha series and gdp and inflation are numerical series.)

GDP inflation country
11 2 Australia
12 3 Austria
13 3 Belgium
10 4 Brazil
8 5 Chile


I want to make a scatpair chart so that x axis is gdp and y axis is inflation. What's more, I want
country names to show up next to each observation plot.

I tried the scarpair command like this:
group graph1 gdp inflation
graph1.scatpair


The problem is that I can't find a way to show country names next to each spot in the
graph. (I tried to use symbol commnad but it's not working).
Is there a way I can do it?

Thanks in advance.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to assign labels to observations in a scatter plot?

Postby EViews Gareth » Tue Sep 13, 2011 8:49 am

Code: Select all

graph1.setelem(1) symbol(obslabel)

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: How to assign labels to observations in a scatter plot?

Postby EViews Glenn » Tue Sep 13, 2011 10:06 am

One comment. The workfile needs to be structured as undated with ID series set to the COUNTRY series.

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: How to assign labels to observations in a scatter plot?

Postby Liu » Tue Sep 13, 2011 10:09 am

I know how to change the frequency to u, but how to change the id series to be "country"?

pagestruct(freq=u) @id(country) ?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to assign labels to observations in a scatter plot?

Postby EViews Gareth » Tue Sep 13, 2011 10:11 am

Code: Select all

pagestruct country

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: How to assign labels to observations in a scatter plot?

Postby Liu » Tue Sep 13, 2011 10:19 am

I tried pagestruct country,
It gives an error saying that "indices do not uniquely identify observations".

I reduced the sample so that there are only three countries whose names are obviously different.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to assign labels to observations in a scatter plot?

Postby EViews Gareth » Tue Sep 13, 2011 10:36 am

You have to remove the duplicate observations from the workfile page (using pagecontract) entirely, rather than from the sample.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to assign labels to observations in a scatter plot?

Postby EViews Gareth » Tue Sep 13, 2011 10:40 am

If you don't want to actually structure your workfile by the country series, you can do this:

Code: Select all

graph1.setobslabel(series) country

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: How to assign labels to observations in a scatter plot?

Postby Liu » Tue Sep 13, 2011 10:49 am

I guess what you are saying is that there should be no dots that have the same
coordinates but different country names? for that I can understand, since two country names would then overlap. but the fact is there is no dots
that share the same coordinates in my series(as you can see in my example).

can you possibly specify what you mean by "removing all the duplicate observations"?


I just also tried the new way: by using graph1.setobslabel(gdp) country,
it says "setobslabel is not a valid view for graph1.
(I removed the (gdp) and it results in the same. )

Many thanks.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to assign labels to observations in a scatter plot?

Postby EViews Gareth » Tue Sep 13, 2011 10:53 am

Try:

Code: Select all

graph1.setobslabel(series) country
The series part should not be replaced.

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: How to assign labels to observations in a scatter plot?

Postby Liu » Tue Sep 13, 2011 11:39 am

I used the command below exactly, but the program keeps telling me that "setobslabel is not a valid view for graph1".

graph1.setobslabel(series) country

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to assign labels to observations in a scatter plot?

Postby EViews Gareth » Tue Sep 13, 2011 11:44 am

graph1 needs to be a graph object, not a group. You can't do it on a group.

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: How to assign labels to observations in a scatter plot?

Postby Liu » Tue Sep 13, 2011 12:59 pm

I just noticed that.
I changed the project to be the graph name rather than the group name. this time there is no error.
But still it doesn't have the country name next to the points. I guess right now the scatpair can not
build any connection between the graph and the third alpha series "country".

I found a chart on eviews help-> basic customization. The "lines and symbols " section gave an exact type of graph
I need, (Matthews(2000) data and storks.wf1). It shows how to do it by clicking but not by commanding.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to assign labels to observations in a scatter plot?

Postby EViews Gareth » Tue Sep 13, 2011 1:33 pm

Code: Select all

create u 20 series x=nrnd series y=nrnd alpha country = "h" group g x y freeze(graph1) g.scatpair graph1.setelem(1) symbol(obslabel) graph1.setobslabel(series) country show graph1

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: How to assign labels to observations in a scatter plot?

Postby Liu » Tue Sep 13, 2011 2:33 pm

I tried your program and it helped a lot in my program: there are
a lot of "h" showing up in the graph. Similar to my graph, different country names
are on the graph. the only thing right now is that the original symbol, which are the
small round dots, are gone.

Can I have both the dots and the name next to it? (you can see that the above program
gives h but no circles or dots for each observation.)

Thanks so much.
Attachments
example.png
example.png (34.3 KiB) Viewed 13130 times


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest