Data visualization with SAS programming

how to add curvelabels if group= option was applied in regressionplot?

Reply
Occasional Contributor
Posts: 8

how to add curvelabels if group= option was applied in regressionplot?

[ Edited ]

Hi, 

 

I tried to add curvelabels to several regression lines. As mentioned above, I used "regressionplot" and "group=" option. The "group=" option conflicted with the "curvelabel=" option. I may also nested "drawtext" in the layout overlay. But if I want to change the size of the figure, the nested "drawtext" will not automaticly fit the size. Is there a better way to fix this problem?

 

Regards,

ttmei

 

My code:

proc template; 
	define statgraph ttmei; 

		begingraph /designwidth=700px designheight=300px border=false; 

			      discreteattrmap name="scatter1" /ignorecase=true;
				  	 value "600-650" / markerattrs=(symbol=circle  size=8 color=blue) lineattrs=(thickness=2 color=blue);
				  	 value "650-700" / markerattrs=(symbol=circle size=8  color=cxff00ff) lineattrs=(thickness=2 color=cxff00ff);
				  	 value "700-750" / markerattrs=(symbol=circle  size=8 color=orange) lineattrs=(thickness=2 color=orange);
				  	 value "750-800" / markerattrs=(symbol=circle size=8  color=green) lineattrs=(thickness=2 color=green) ;
				  	 value "800-850" / markerattrs=(symbol=circle size=8  color=black) lineattrs=(thickness=2 color=black) ;
				  	 value "850-900" / markerattrs=(symbol=circle size=8  color=brown) lineattrs=(thickness=2 color=brown) ;
				  	 value "900-950" / markerattrs=(symbol=circle size=8  color=yellow) lineattrs=(thickness=2 color=yellow) ;
				  	 value "950-1000" / markerattrs=(symbol=circle size=8  color=red) lineattrs=(thickness=2 color=red) ;
				  	 value "1000-1100" / markerattrs=(symbol=circle size=8  color=purple) lineattrs=(thickness=2 color=purple) ;
				  	 value "1100-1300" / markerattrs=(symbol=circle size=8  color=darkgreen) lineattrs=(thickness=2 color=darkgreen) ;
			      discreteattrvar attrvar=scatter var=dor attrmap="scatter1";

			layout lattice /rows=1 columns=2;

				layout overlay/
					yaxisopts=(display=(ticks tickvalues line) offsetmin=0.1 offsetmax=0 tickvalueattrs=(FAMILY="Arial" SIZE=10pt)
							linearopts=(viewmin= 0 viewmax=0.6 thresholdmin=0) labelattrs=(FAMILY="Arial" SIZE=10pt))
					xaxisopts=(display=(ticks tickvalues line) offsetmin=0 offsetmax=0 tickvalueattrs=(FAMILY="Arial" SIZE=10pt)
							linearopts=(viewmin= 0 viewmax=1 thresholdmin=0) labelattrs=(FAMILY="Arial" SIZE=10pt)); 
					scatterplot  y=kx x=Mf/group=scatter name="dot1"; 
					regressionplot y=kx x=Mf/group=scatter  name="line1";
/*					mergedlegend "dot1" "line1"/title="Dry density" exclude=( "500-600" "1400-1700" ".") location=inside border=false across=2 halign=right valign=bottom*/
/*													valueattrs=(size=10);	*/
					entry halign=left "(A)"/location=inside valign=top textattrs=(family="Arial" size=10pt) ;	
				 endlayout; 

				layout overlay/
					yaxisopts=(display=(ticks tickvalues line label) label="Tc/Dd" offsetmin=0 offsetmax=0 tickvalueattrs=(FAMILY="Arial" SIZE=10pt)
							linearopts=(viewmin= 0.2 viewmax=0.8 thresholdmin=0) labelattrs=(FAMILY="Arial" SIZE=10pt))
					xaxisopts=(display=(ticks tickvalues line) offsetmin=0 offsetmax=0 tickvalueattrs=(FAMILY="Arial" SIZE=10pt)
							linearopts=(viewmin= 0 viewmax=1 thresholdmin=0) labelattrs=(FAMILY="Arial" SIZE=10pt)); 
					scatterplot x=mf y=cd/ markerattrs=(symbol=circle size=8 color=black);
					regressionplot x=mf y=cd/lineattrs=(thickness=2 color=black) ;
					entry halign=left "(B)"/location=inside valign=top textattrs=(family="Arial" size=10pt) ;	
					layout gridded/columns=1 rows=2 location=inside halign=right valign=bottom;
		                 entry  halign=right "Y=0.32X+0.31"/
								textattrs=(family="Arial" size=10pt);
		                 entry  halign=right "R"{sup '2'}"=0.99; P<0.05"/
								textattrs=(family="Arial" size=10pt);
				    endlayout;
				 endlayout; 

		       rowheaders;
		                 entry "Tc (W m" {sup '-1'} " K" {sup '-1'}")" /rotate=90 textattrs=(family="Arial" size=10pt);
		       endrowheaders;

		        sidebar / align=bottom;
			        entry halign=center "Wc (g g"{sup '-1'}")"/valign=bottom location=outside
			              textattrs=(FAMILY="Arial" SIZE=10pt) pad=(bottom=8px);
		        endsidebar;

			endlayout; 
		endgraph; 
	end; 
run; 
ods  html image_dpi=300  ;
proc sgrender data=tcmax.tc template="ttmei" ; 
run; 

 

Super User
Super User
Posts: 7,711

Re: how to add curvelabels if group= option was applied in regressionplot?

Well, I had a quick search on the blog for graphs:

http://blogs.sas.com/content/graphicallyspeaking/?s=curvelabels

There is a tag at the bottom for full code examples.  They are SGPLOT, however with the tmplout= option on proc sgplot you can see the underlying template code generated (I find that is a quick way to find syntax).  Would markerchar work? 

Occasional Contributor
Posts: 8

Re: how to add curvelabels if group= option was applied in regressionplot?

Thank you for your reply. I have tried "markerchar" and it's not work in regressionplot. Sorry. 

 

Regards,

ttmei

Super User
Super User
Posts: 7,711

Re: how to add curvelabels if group= option was applied in regressionplot?

Sorry, I don't understand "its not work in regression", do you mean its not an optin for that type of graph?  If so then just add a scatter over the reg plot with options you need, and set the scattter to have very small points so they don't show.  That is a basic concept of GTL is that you overlay various graphs with various options to get output you want, one statement is generally not going to do everything.

For instance, you could pull reg values out from a proc reg step, then use that data to plot an scatter.

proc reg...;

  model...;

  ods output ParameterEsitmates=pe...;

run;

proc sgplot...

Occasional Contributor
Posts: 8

Re: how to add curvelabels if group= option was applied in regressionplot?

Yes, I think add a scatter on the reg line is a good idea. Should work. Thank you.

Super User
Posts: 11,118

Re: how to add curvelabels if group= option was applied in regressionplot?

Which version of SAS are you running. There have been notable enhancements for graphics options in the last couple of releases.

SAS Super FREQ
Posts: 1,139

Re: how to add curvelabels if group= option was applied in regressionplot?

It would help if you add the full program with data to see what you are getting and what you want.  it also helps to know what SAS release you have.  

 

That said, CURVELABEL=string is used to put a string curve label for non-grouped case.  If you want to label each regression curve by the group value, I suggest you use an overlaid SCATTERPLOT that has only the the point you want (maybe last) with a DATALABEL=column to display the group values.  You can set the markersize for the scatter to zero.  With SAS 9.4M3, you can also use TEXTPLOT.

Occasional Contributor
Posts: 8

Re: how to add curvelabels if group= option was applied in regressionplot?

Thank you for your suggestions! Unfortunately my SAS version is 9.4 1M2. But I will try  SCATTERPLOT to display the label of the last point value. This should work. Thank you again.

 

Occasional Contributor
Posts: 8

Re: how to add curvelabels if group= option was applied in regressionplot?

Hi, 

 I'm using SAS 9.4 1M2.

Ask a Question
Discussion stats
  • 8 replies
  • 444 views
  • 2 likes
  • 4 in conversation