Page 1 of 2
How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 8:40 am
by Liu
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.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 8:49 am
by EViews Gareth
Code: Select all
graph1.setelem(1) symbol(obslabel)
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:06 am
by EViews Glenn
One comment. The workfile needs to be structured as undated with ID series set to the COUNTRY series.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:09 am
by Liu
I know how to change the frequency to u, but how to change the id series to be "country"?
pagestruct(freq=u) @id(country) ?
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:11 am
by EViews Gareth
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:19 am
by Liu
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.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:36 am
by EViews Gareth
You have to remove the duplicate observations from the workfile page (using pagecontract) entirely, rather than from the sample.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:40 am
by EViews Gareth
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
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:49 am
by Liu
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.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 10:53 am
by EViews Gareth
Try:
Code: Select all
graph1.setobslabel(series) country
The
series part should
not be replaced.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 11:39 am
by Liu
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
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 11:44 am
by EViews Gareth
graph1 needs to be a graph object, not a group. You can't do it on a group.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 12:59 pm
by Liu
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.
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 1:33 pm
by EViews Gareth
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
Re: How to assign labels to observations in a scatter plot?
Posted: Tue Sep 13, 2011 2:33 pm
by Liu
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.