Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: complicated scatterplot with connected points

From   Antoine Terracol <>
Subject   Re: st: RE: complicated scatterplot with connected points
Date   Sun, 05 Dec 2010 16:17:14 +0100


is this what you are looking for?

input str10 id_city x1 y1 x2 y2 x3 y3 str10 city1 str10 city2 str10 city3 "Portland" 34 64 23 78 54 67 "Portland1" "Portland2" "Portland3" "Chicago" 53 72 33 52 91 77 "Chicago1" "Chicago2" "Chicago3" "Boston" 50 70 30 50 90 70 "Boston1" "Boston2" "Boston3"

reshape long x y city, i(id_city) j(period)

sort id_city period

twoway (connected y x if id_city=="Portland", mlabel(city)) ///
(connected y x if id_city=="Chicago", mlabel(city)) ///
(connected y x if id_city=="Boston", mlabel(city))


On 05/12/2010 15:54, Gisella Young wrote:
Dear Nick (and others),

Thank you for the hint but unfortunately I have not been able to see how this solves the problem. Reshaping the data as you suggest is not a problem, but I still can't see how to connect the scatterplot points with lines in the specific way needed. Perhaps you (or someone else) could give a further clue, or elaborate some of the other various approaches that you mention exist?

Thanks for the help.


--- On Fri, 12/3/10, Nick Cox<>  wrote:

From: Nick Cox<>
Subject: st: RE: complicated scatterplot with connected points
To: "''"<>
Date: Friday, December 3, 2010, 5:44 PM
There are various approaches to this.
One is to restructure your data so that the graphics command
becomes easier.

reshape long x y, i(city)

Spelling is Stata.


Gisella Young

I want to draw a slightly complex scatterplot in STATA and
have not been able to find a way how. For each city I have 3
points (each with a x- and y-coordinate) for 3 different
years. I can use the -twoway- graphics command to do three
overlaid scatterplots so that each city has 3 points, one
for each year. The tricky part: to CONNECT (with a line) the
three points for each city, so as to trace its path over

The command I am using at the moment, for the basic
scatterplot without connecting lines, is:
  twoway (scatter x y1, sort mlabel(city1)) (scatter x2 y2,
sort mlabel(city2)) (scatter x3 y3, sort mlabel(city3))

My data has the following structure:

x1   y1   x2
x3   y3   city1
   city2      city3

34   64   23
54   67   Portland1
Portland2  Portland3
    53   72   33
91   77   Chicago1   Chicago2   Chicago3
Boston      etc

I would greatly appreciate any suggestions. Thank you!

*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index