BookmarkSubscribeRSS Feed
Denali
Quartz | Level 8

Hi,

 

Attached is the spagetti plot that I made. Does anyone know how to add a smooth line (mean or median) to this figure?

 

Below is my SAS code:


proc sgplot data=test2;
where AKI=1 & survive_5yr = 1;
series x=year y=eGFR_a /group=ID ;
keylegend 'grouping' / type=linecolor;
label eGFR_a = eGFR year = Year;
run;

 

Many thanks in advance!

 

 

 

8 REPLIES 8
ChrisNZ
Tourmaline | Level 20

1. Do not attach MS Office files, many will/can not download these.

2. Include images as ... images, there's a button for that

3. Did you try adding a series statement?

4. It's a good idea to include code that we can run. For example using one of the sample data sets in the SASHELP library.

 

Denali
Quartz | Level 8
Sorry, I didn’t see the imagine button. Where is it?
What series can I add for the smooth line? I would like to add a mean or median into the plot.
ChrisNZ
Tourmaline | Level 20
1. The camera button
2. Calculate the mean and plot it
Ksharp
Super User
Maybe it is not what you want.But could try LOESS

loess x=year y=eGFR_a ;
Denali
Quartz | Level 8

SGPlot.png


proc sgplot data=test2;
where AKI=1 & survive_5yr = 1;
series x=year y=eGFR_a /group=ID ;
loess x=year y=eGFR_a ;
keylegend 'grouping' / type=linecolor;
label eGFR_a = eGFR year = Year;
run;

 

It does not look like what I expected. I would like to plot a mean in the middle of the figure, if possible....

Ksharp
Super User
Well. Could you calculate mean of eGFR_a within a year .And plot it on your own ?
ballardw
Super User

Mean or median of what exactly?

How many lines of spaghetti (group=ID values) are there? If you have 10 lines are you looking to add 10 "means"?

You

 

I might be tempted to add:

reg x=year y=eGFR_a /group=ID ;

 

to show a "best fit" line associated for each group.

 

Or summarize you data to find the desired mean or median and use a REFLINE statement to plot those values.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2019 views
  • 0 likes
  • 4 in conversation