2
votes

I have a simple SAS data set I am plotting as a scatter plot, my two questions are:

  1. I am trying to adjust the y-axis without excluding the (0.02,51) data point but I need the y-axis to only show 60 to 160 by 20. When I define this it excludes that specific data point and I don't know how to fix it.
  2. I cannot figure out how to add a custom fitted curve and display the formula. Here is my line: Y=(160.3*x)/(0.0477+x)

Here is my code:

proc sgplot data=work.sas1;
title 'Puromycin Uptake Experiments';
scatter x=x y=y/ markerattrs=(color=black);
xaxis Label='Reactant Concentration X (mg/l)';
yaxis Label='Reaction Velocity Y (mg/s)' values=(60 to 160 by 20);
run;

Can anyone please help?

2
If the y axis only goes from 60 to 160, how can the plot include a point with y=51? Do you want a y axis that extends to, say, 50 but only labels down to 60?Quentin

2 Answers

2
votes

Try using OFFSETMIN= to extend the yaxis beyond your values.

Add a new variable, y_hat with the values of your formula. Plot that and label it appropriately.

data sas1;
x=.02; y=67; output;
x=.02; y=51; output;
x=.06; y=84; output;
x=.06; y=86; output;
x=.11; y=98; output;
x=.11; y=115; output;
x=.22; y=131; output;
x=.22; y=124; output;
x=.56; y=144; output;
x=.56; y=158; output;
x=1.1; y=160; output;
run;

data sas1;
set sas1;
Y_hat=(160.3*x)/(0.0477+x);
run;

proc sgplot data=work.sas1;
title 'Puromycin Uptake Experiments';
scatter x=x y=y/ markerattrs=(color=black);
series x=x y=y_hat / curvelabel="Y=(160.3*x)/(0.0477+x)";
xaxis Label='Reactant Concentration X (mg/l)';
yaxis Label='Reaction Velocity Y (mg/s)' offsetmin=.1 values=(60 to 160 by 20);
run;

Produces: enter image description here

1
votes

y axis

There are a couple y-axis options can affect the axis rendering. consider offsetmin or a tweaked list in the values=

formula line

There is no formula statement in SGPLOT so you have to create an auxiliary column for drawing the formula in a series. Some times you can align the x's of the data with the x's of the formula. However, for the case of wanting a higher density of x's for the formula you stack the scatter and formula data. Don't get hung up on the chunks of missing values and any feelings of wastefulness.

I am not sure where your curve fit comes from, but statistical graphics (the SG in SGPLOT) has many features for fitting data built into it.

* make some example data that looks something like the fit curve;
data have;
  do x = 0.03 to 1 by 0.0125;
    y = ( 160.3 * x ) / ( 0.0477 + x ) ;
    y + round ( 4 * ranuni(123) - 8, 0.0001);
    output; 
    x = x * ( 1 + ranuni(123) );
  end;

  x = 0.02;
  y = 51;
  output;
run;

* generate the series data for drawing the fit curve;
* for complicated formula you may want to adjust step during iteration;
data fit;
  step = 0.001;
  do x = 0 to 1;
    y = ( 160.3 * x ) / ( 0.0477 + x ) ;
    output;
    * step = step + smartly-adjusted-x-increment;
    x + step;
  end;
  keep x y;
  rename x=xfit y=yfit;
run;

* stack the scatter data and the curve fit data;
data have_stack_fit;
  set have fit;
run;

proc sgplot data=have_stack_fit;
  scatter x = x y = y;
  series  x = xfit y = yfit / legendlabel="( 160.3 * x ) / ( 0.0477 + x )";

  yaxis values = (0 60 to 160 by 20) ;
run;