Scatter plot labels
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Scatter plot labels
Hello,
I have created a scatter plot which contains about 100 items and I want to label some of them but not all. Could you please tell me if there is an easy way to do this? Moreover, is it possible to change the appearance (color and size) of a single point in a scatter plot?
Thanks,
Javier
I have created a scatter plot which contains about 100 items and I want to label some of them but not all. Could you please tell me if there is an easy way to do this? Moreover, is it possible to change the appearance (color and size) of a single point in a scatter plot?
Thanks,
Javier
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13585
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Scatter plot labels
You can't change the size of individual points, nor can you only label some.
I suppose you could always "trick" EViews into doing it by splitting your series into two separate series, graphing them both on the same graph, but only choosing to label one of them.
I suppose you could always "trick" EViews into doing it by splitting your series into two separate series, graphing them both on the same graph, but only choosing to label one of them.
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Scatter plot labels
For individual labels, try this. Make an alpha series with the labels you want, leaving the other elements blank. Then under Lines & Symbols in the graph options dialog set Symbol/Obs label to Obs. Label. Then under Obs/Date Axis set "Optional alpha..." to the alpha series you created.
Re: Scatter plot labels
That works well if there are no auxiliary graphics such as a linefit.
If there is a linefit how would you exclude the second line?
In my case, say you have panel data with id=countries, time from 1980 to 2010 and variables are _x and _y. I want to plot a scatter of x and y for one period only (e.g. 2009) in the sample and highlight the values of some countries in _y, so I create a new series _y1 with these observations and I do:
this will show two regression lines (one for _x,_y and one for _x,_y1). How could I get rid of the second regression line?
Thanks,
Javier
If there is a linefit how would you exclude the second line?
In my case, say you have panel data with id=countries, time from 1980 to 2010 and variables are _x and _y. I want to plot a scatter of x and y for one period only (e.g. 2009) in the sample and highlight the values of some countries in _y, so I create a new series _y1 with these observations and I do:
Code: Select all
group g3 _x _y _y1
g3.scat linefit(yi)
Thanks,
Javier
Re: Scatter plot labels
Thanks for the tip startz, I'll give it a try.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13585
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Scatter plot labels
Yeah, Startz's method is the only way to do it with fit lines added, although it still doesn't fix the different size points problem.
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Scatter plot labels
This got explained to me by a friend who I'll just call "DL." The trouble is I forget how to do it and he has to remind me periodically.
So if someone could remember all this when I next forget....
So if someone could remember all this when I next forget....
Re: Scatter plot labels
Hi Startz,
I have tried to follow up the steps you suggested a few weeks back on how to replace the obs labels text. These were:
(i) Make an alpha series with the labels you want, leaving the other elements blank.
(ii) Then under Lines & Symbols in the graph options dialog set Symbol/Obs label to Obs. Label.
(iii) Then under Obs/Date Axis set "Optional alpha..." to the alpha series you created.
I can't follow the last step as the "Optional alpha" option doesn't appear on my menu (I have attached the screen snapshot). I am using v7.
How do you do this?
Thanks,
Javier
I have tried to follow up the steps you suggested a few weeks back on how to replace the obs labels text. These were:
(i) Make an alpha series with the labels you want, leaving the other elements blank.
(ii) Then under Lines & Symbols in the graph options dialog set Symbol/Obs label to Obs. Label.
(iii) Then under Obs/Date Axis set "Optional alpha..." to the alpha series you created.
I can't follow the last step as the "Optional alpha" option doesn't appear on my menu (I have attached the screen snapshot). I am using v7.
How do you do this?
Thanks,
Javier
- Attachments
-
- Obs_Date.JPG (46.37 KiB) Viewed 22917 times
Re: Scatter plot labels
If you look @ your userform, it looks like there is a button "custom...." that probably controls this feature.
Is this feature (using an alpha series to add custom labels) only available in Eviews 7? hoping to resurrect this conversation to get a few more answers.
thanks,
steve
Is this feature (using an alpha series to add custom labels) only available in Eviews 7? hoping to resurrect this conversation to get a few more answers.
thanks,
steve
Re: Scatter plot labels
I came up with a program that has worked for me for various panels. It works as a standalone program which is called from another program once two pieces of info are provided as detailed below: %cht_string and a pool named "iso", with data in panel format.
Say you have a group of variables for output gap and inflation like aut_gap bel_gap, etc. and aut_infl bel_infl etc. The example below illustrate how the labels are set:
pool iso aut bel esp prt
pagestack(page=mypanel) iso @ ?_gap ?_infl
group pair1 _gap _infl
freeze(mychart) pair1.scat
%cht_string="mychart"
include set_obs_labels.prg
mychart.options linepat
mychart.setelem(1) symbol(13) symbolsize(3xl)
where:
set_obs_labels.prg
Hope it helps.
Javier
Say you have a group of variables for output gap and inflation like aut_gap bel_gap, etc. and aut_infl bel_infl etc. The example below illustrate how the labels are set:
pool iso aut bel esp prt
pagestack(page=mypanel) iso @ ?_gap ?_infl
group pair1 _gap _infl
freeze(mychart) pair1.scat
%cht_string="mychart"
include set_obs_labels.prg
mychart.options linepat
mychart.setelem(1) symbol(13) symbolsize(3xl)
where:
set_obs_labels.prg
Code: Select all
'Programmed by Javier Sánchez on January 2010
'Required values from external program:
'------------------------------------------------------
'strings: %cht_string : string with the name of the charts to label
'alphas: iso - contains the list of identifiers
'
'Elements used by the program:
'-------------------------------------------
'Variables used: !__nobs, !__obs, !_j, !_o
'Series: withinid, _id
'Tables: _obs_label
'Strings: %cht
series withinid = @obsid
series _id = @obsnum
!__nobs=@sum(withinid)
'Stores the labels on a table
table(!__nobs,1) obs_label
!__obs=1
for !_j=1 to @max(_id)
if withinid(!_j)>0 then
obs_label(!__obs,1)=iso(!_j)
!__obs=!__obs+1
endif
next !_j
'Names the observation labels for each chart
for %cht {%cht_string}
!_o=1
for !_j=1 to !__obs-1
%myobs=obs_label(!_j,1)
{%cht}.setobslabel(!_o) %myobs
!_o=!_o+1
{%cht}.setobslabel(!_o) ""
!_o=!_o+1
next !_j
next %_cht
'delete withinid _id obs_label Javier
Re: Scatter plot labels
I forgot to add that in order to plot the scatter you have to restrict your sample to a single observation, such as:
smpl 2010 2010
and that once the program set_obs_labels.prg is run it gives an error which is inconsequential (related I think to labeling the last obs as blank). The labels shown are the cross-section identifiers of the pool iso.
Regards,
Javier
smpl 2010 2010
and that once the program set_obs_labels.prg is run it gives an error which is inconsequential (related I think to labeling the last obs as blank). The labels shown are the cross-section identifiers of the pool iso.
Regards,
Javier
Re: Scatter plot labels
Javier,
hey, thanks for this code. the clue that I needed here was this 'setobslabel' function. that is the workhorse here. really appreciate you listing.
to add to the conversation and as an aside, something that I regularly do is take a group of time series data and pull various cross-sections out for regressions, optimizations, etc.. Recently, I have a need to chart cross-sections from a specific date in the time-series. one neat set of features of eviews library that go beyond their math aspects are the matrix functions. I pull out a row from a group on a specific date (lets say my 'x' data) and a row from another group on another specific date (further, my 'y' data) and put both into a matrix. If I order my data properly in the columns of the matrix, I have x-y data that I can plot as such. create a scatter graph from the matrix.
I also use tables A LOT as utility tools. If I keep my code clean, everything is done in the same order and the utility table can hold the observation labels. Use the following code to apply the labels to the graph created from the matrix.
This should work with any workfile type as it is merely applying the setobslabel function to a chart.
Javier, thanks again for the post.
Steve
hey, thanks for this code. the clue that I needed here was this 'setobslabel' function. that is the workhorse here. really appreciate you listing.
to add to the conversation and as an aside, something that I regularly do is take a group of time series data and pull various cross-sections out for regressions, optimizations, etc.. Recently, I have a need to chart cross-sections from a specific date in the time-series. one neat set of features of eviews library that go beyond their math aspects are the matrix functions. I pull out a row from a group on a specific date (lets say my 'x' data) and a row from another group on another specific date (further, my 'y' data) and put both into a matrix. If I order my data properly in the columns of the matrix, I have x-y data that I can plot as such. create a scatter graph from the matrix.
I also use tables A LOT as utility tools. If I keep my code clean, everything is done in the same order and the utility table can hold the observation labels. Use the following code to apply the labels to the graph created from the matrix.
Code: Select all
'parameters
'******************************
'Table >>> named obs_label with continuous, in order,
'list of the data labels (order matches your listing in your data set)
'beginning on row 1, column 1
'Graph>>> named _tmp_chart as a cross-sectional graph holding the points.
'*******************************
'loop through the obs_label table
for !i = 1 to 1000
'if to end of obs labels, exit the loop
If obs_label(!i,1) = "" then
exitloop
endif
'create a string list of the observation labels in the chart.
%label_list = %label_list+" "+obs_label(!i,1)
next
'now have a list of the labels that you want to apply to the points.
'use the setobslabel function to apply the labels.
_tmp_chart.setobslabel {%label_list}
Javier, thanks again for the post.
Steve
Re: Scatter plot labels
Hi Steve,
As you saw from my previous posts the way I do the scatter plots is by creating a panel, but reading your reply I think you have come up with a less complicated way to do it. I can't figure out how you make your matrix with a subset of a grouped series though, could you give an example please?
Thanks,
Javier
As you saw from my previous posts the way I do the scatter plots is by creating a panel, but reading your reply I think you have come up with a less complicated way to do it. I can't figure out how you make your matrix with a subset of a grouped series though, could you give an example please?
Thanks,
Javier
Re: Scatter plot labels
Javier,
'*****************
This is for v. 6...I can't imagine that v7 is different
'*****************
I think that it will probably be easiest if I just give you the steps with the functions & procs that I use. I am building some code at this moment and I glanced at it....it is dynamic with a lot of project specific objects so probably best to do it this way:
1) you have a group of time series items (lets say 1 year GDP growth for G10).
2) determine the date that you want to get a cross section for and turn that into an observation using @dtoo()
3) now, turn your group into a matrix using the stomna() proc. This brings in any NA's so that you can match up your observation number with a row in the matrix.
4) You have a matrix and you have an observation number. Now pull out the row of the matrix into a vector using @rowextract().
Vector {%Vector} = @transpose(@rowextract(TmpMtx, !lastObs))
above I created a column vector by transposing the row from the matrix.
5) this is either your x data or your y data. Repeat steps 1-4 above to get the data for the other side of the xy pair (for simplicity you could compare to an earlier data in your time series to see how growth momentum compares).
6) you should now have two vectors. create a blank matrix to hold the two data vectors. that should be column vectors with equal dimensions. so use something like:
matrix(@rows({%xvector}), 2) TmpMtx
7) you now have a matrix called TmpMtx with two columns and the same number of rows as your two xy column vectors. put the vectors in the matrix:
colplace(TmpMtx, {%xvector}, 1) 'putting the xvector in the 1st column of the TmpMtx
colplace(TmpMtx, {%yvector}, 2) 'putting the yvector in the 2nd column of the TmpMtx
you've now got TmpMtx with two columns and you can use the various charting features as you've already done in other posts.
I used:
freeze({%gph}) TmpMtx.scat linefit
All of this seems a little cumbersome at first but as you get used to using the method, it becomes VERY useful. I use the basic idea of this technique for all sorts of time dynamic calculations.
hope that is helpful.
Steve
p.s. be sure to clean up your objects along the way. if you are doing multiple graphs this can make a mess in your workfile.
'*****************
This is for v. 6...I can't imagine that v7 is different
'*****************
I think that it will probably be easiest if I just give you the steps with the functions & procs that I use. I am building some code at this moment and I glanced at it....it is dynamic with a lot of project specific objects so probably best to do it this way:
1) you have a group of time series items (lets say 1 year GDP growth for G10).
2) determine the date that you want to get a cross section for and turn that into an observation using @dtoo()
3) now, turn your group into a matrix using the stomna() proc. This brings in any NA's so that you can match up your observation number with a row in the matrix.
4) You have a matrix and you have an observation number. Now pull out the row of the matrix into a vector using @rowextract().
Vector {%Vector} = @transpose(@rowextract(TmpMtx, !lastObs))
above I created a column vector by transposing the row from the matrix.
5) this is either your x data or your y data. Repeat steps 1-4 above to get the data for the other side of the xy pair (for simplicity you could compare to an earlier data in your time series to see how growth momentum compares).
6) you should now have two vectors. create a blank matrix to hold the two data vectors. that should be column vectors with equal dimensions. so use something like:
matrix(@rows({%xvector}), 2) TmpMtx
7) you now have a matrix called TmpMtx with two columns and the same number of rows as your two xy column vectors. put the vectors in the matrix:
colplace(TmpMtx, {%xvector}, 1) 'putting the xvector in the 1st column of the TmpMtx
colplace(TmpMtx, {%yvector}, 2) 'putting the yvector in the 2nd column of the TmpMtx
I used:
freeze({%gph}) TmpMtx.scat linefit
All of this seems a little cumbersome at first but as you get used to using the method, it becomes VERY useful. I use the basic idea of this technique for all sorts of time dynamic calculations.
hope that is helpful.
Steve
p.s. be sure to clean up your objects along the way. if you are doing multiple graphs this can make a mess in your workfile.
Re: Scatter plot labels
Hi Steve,
No wonder I couldn't come up with the code!
Thank you very much for the detailed explanations, I didn't know that you could make scatter plots with a matrix and this is a better idea than creating a pool/panel page for each chart as I was doing.
Regards,
Javier
No wonder I couldn't come up with the code!
Thank you very much for the detailed explanations, I didn't know that you could make scatter plots with a matrix and this is a better idea than creating a pool/panel page for each chart as I was doing.
Regards,
Javier
Who is online
Users browsing this forum: No registered users and 2 guests
