Gplot--designate different lines for different groups

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Gplot--designate different lines for different groups

Hi,

Thanks in advance for your help.  I'd like to create a plot that shows different lines for two different groups of people.  The data are participation counts (number of comments made to group discussions) over three different days.  The data are in the "long format"--each person has three lines, one for each day.  I can generate the plot of participation*day for each participant, but I'd like to show that some of the participants were actually facilitators, and use dashed lines for them.  Here's my code:

title "Participation Over Time With Facilitators";

symbol1 value = circle color = black interpol = join repeat = 180;

axis2 label=(angle=90);

proc gplot data=all_days_with_fac_no_missing;

  plot part*newday = id / vaxis = axis2 nolegend;

  format newday dayf.;

run;

The plot generated by the code is attached.  Again, I'd like to show the facilitators with dashed lines in the plot--the variable that designates facilitators from regular participants is "facil".  The "by" command creates to separate plots, but that's not what I want--I'd like to overlay them, if possible.

Thank you!.

Joe


Accepted Solutions
Solution
‎08-10-2012 05:06 PM
Super User
Posts: 10,483

Re: Gplot--designate different lines for different groups

You may need to explicitly reset REPEAT=1;

before reruning the program. The graph symbols axis and legends can hold on to a lot of options you wouldn't expect when reusing.

Or

proc goptions symbol;run; to see what your actual current symbol statements look like. You may need to explicitly

View solution in original post


All Replies
Super User
Posts: 10,483

Re: Gplot--designate different lines for different groups

How many values do you have for ID? What are the values and which one is the "facilitator"?

If there are only 2 values for ID then: remove the repeat from symbol1;

Create a SYMBOL2 with a different color and and add al line type  such as LINE=2 (any value from 2 to 46 will generate a different dash, dot or dast dot line).

If you have LOTS of ID values you should create a format that assigns them to facilitator and non-facilitator categories and apply that format in gplot.

Occasional Contributor
Posts: 18

Re: Gplot--designate different lines for different groups

Hi,

Thanks for your response.  I see what you are saying. I have ID values for each participant, roughly 150 regular participants and 25 facilitators.  Could I just set the Symbol1 statement to repeat for the number of non-facillitators (sorted so that they are first in the data file), and then the Symbol2 statement for the remainder (with a dashed line)?  Let me work on that, and I'll post my code and graph when I get the chance.

Joe

Occasional Contributor
Posts: 18

Re: Gplot--designate different lines for different groups

That did it.  I just made sure the repeat statement for symbol1 equaled the number of non-facillitators, then put another repeat statement in Symbol2 that equalled the number of facilitators.  Code is below:

title "Participation Over Time With Facilitators";

symbol1 value = circle color = black interpol = join repeat = 134;

symbol2 value = circle color = red interpol = join repeat = 50;

axis2 label=(angle=90);

proc gplot data=all_days_with_fac_no_missing;

  plot part*newday = id / vaxis = axis2 nolegend;

  format newday dayf.;

run;

Thanks again for your help.

Joe

Super User
Posts: 10,483

Re: Gplot--designate different lines for different groups

I think that you might want to explore the use of the format on the ID variables, at least as a technique if not for this use.

something like:

value ids

1,2,3,5,10, (etc) = 'Faciliator'

4,6,7,8, (etc) ='Participant'

;

Reasons:
Legends would have the correct labels associated with the color / line combinations. I am guessing that you suppressed the legend intially because you had 175 legend entries and very little graph.

If you were to group your data on some other variable such as an orginzation or geographic location using a BY group you may find that rying to use repeat to get the correct number of records displayed correctly a nightmare.

Also with a relatively simple format change you could designate group A vs group B faciliators and particpants with just the ID variable. I know that looks like a lot of work but you may be able to use a CNTLIN dataset with proc format to make the ID format(s) relatively easily depending on other data available.

Occasional Contributor
Posts: 18

Re: Gplot--designate different lines for different groups

Actually, the format issue is easy, as all the regular participants have ids less than 10000, facilitators above.  But the question is how to use the format in the plot.  Here's my code;

title "Participation Over Time With Facilitators";

symbol1 value = circle color = black interpol = join;

symbol2 value = square color = red l=2 interpol = join;

axis2 label=(angle=90);

proc gplot data=all_days_with_fac_no_missing;

  plot part*newday = id / vaxis = axis2;

  format newday dayf. id idf.;

run;

I removed the "repeat" and "nolegend" statements and get the right legend (one each for facilitators and participants), but not the correct coloring/lines in the actual plot for the two symbol statements.  Everything is black and uses the circle.  

Thanks again.  You are correct that it would be a pain if I had to use repeat statements all the time.  Getting close.

Joe

Solution
‎08-10-2012 05:06 PM
Super User
Posts: 10,483

Re: Gplot--designate different lines for different groups

You may need to explicitly reset REPEAT=1;

before reruning the program. The graph symbols axis and legends can hold on to a lot of options you wouldn't expect when reusing.

Or

proc goptions symbol;run; to see what your actual current symbol statements look like. You may need to explicitly

Occasional Contributor
Posts: 18

Re: Gplot--designate different lines for different groups

That's the ticket!  Adding "repeat=1" to each symbol statement worked like a charm.  Thanks so much.

Best,

Joe

Occasional Contributor
Posts: 18

Re: Gplot--designate different lines for different groups

Here's another wrinkle.  I'd like to create plots by groups, which ought to be simple enough with the "by" statement (with the data sorted by group).  But doing so produces plots for each day for each group, rather than the plots for all three days for each group on the same plot. See the attached file.  Any thoughts on why gplot would do this and any potential remedies?  Thanks in advance.

Here's the code:

title "Participation Over Time With Facilitators";

symbol1 value = circle color = black interpol = join repeat=1;

symbol2 value = square color = red l=2 interpol = join repeat=1;

axis2 label=(angle=90);

proc gplot data=all_days_with_fac_no_missing;

  plot part*newday = id / vaxis = axis2;

  format newday dayf. id idf.;

by group;

run;

Joe

Super User
Posts: 10,483

Re: Gplot--designate different lines for different groups

How do you define your variable Group? Was it read in or created in a data step? If the last, what was the code to create it.

A quick diagnostic would be

proc freq data= all_days_with_fac_no_missing; table group*newday/missing;run;

I suspect you'll find that each group is define only on one value of the day variable. It could be that it was only defined on the first day and someone assumed the value would carry over to the other days. In which case you'll want ot go back to the code making your plot dataset and ensure that the group id is present on each record - before sorting.

A code snippet that may be helpful if group exists in the data set used to creat the plot data set assuming my idea of group missing on other than first records AND the order hasn't been changed:

retain lastgroup .;

if group ne . then lastgroup= group;

if group = . then group=lastgroup;

Occasional Contributor
Posts: 18

Re: Gplot--designate different lines for different groups

That sound you heard was me slapping my forehead.  Group membership changes across each day, so the only plots I can generate are at the individual level...

Thanks for your reply.

Best,

Joe

Occasional Contributor
Posts: 7

Re: Gplot--designate different lines for different groups

Maybe you can create an annotate dataset...

data anno;

length function color $8;

retain xsys ysys '2' when 'a';

set data;

by id;

function='symbol';

x=newday;                                                                                                                            

   y=part;

if then text='square';-- use this statement to create specify line style

else text='dot';

     size=0.8;

if  then color='red';

if  then color='green'; color code lines....

output;

run;

Maybe this can help

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 727 views
  • 3 likes
  • 3 in conversation