BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aerianna9
Fluorite | Level 6

Hello all, 

 

I'm trying to change the size of a scatterplot to show a 7x7 grid (a total of 49 cells), instead of what the scatterplot automatically generates. Can anyone tell me how I can change the amount of squares on the grid? 

 

Also, I'm needing help trying to define how many data points (point count) in each square on the grid by producing a data table 

 

Thanks in advance, 

Aerianna

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Aerianna9 wrote:
This was helpful for the grid. Now I'm needing help with the point count for each grid cell. Any ideas?

One way is to create a custom format for each range of value with the desired boundaries for cells. Then apply that format in procedure to count things.

 

An example using @Ksharp's example data set modified to create "nicer" cell boundaries:

data have;
call streaminit(123);
do i=1 to 100;
x=rand('uniform')*7;
y=rand('uniform')*7;
output;
end;
run;
proc format; value xcell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; value ycell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; run; proc sort data=have; by descending y; run; proc tabulate data=have; class x; class y/ order=data; format x xcell. y ycell.; table y, x *n=' ' / misstext='0' ; run;

The 7 x 7 cell boundaries were relatively easy due to the way the data set was made so each variable has values in the [0,7] range. In a more typical fashion you would need to do more work with the formats (and your actual data). This relatively easily is made to match a VALUES option on a graph axis statement.

 

The sort was so the cell count orientation would match the graph closer.

View solution in original post

7 REPLIES 7
ballardw
Super User

Example data

What the boundaries of the cells should be.

The code of your current scatterplot.

 

Typically scatterplots do not have "cells", so you need to provide some sort of example details.

Aerianna9
Fluorite | Level 6
Sure, I can provide more detail.
Aerianna9
Fluorite | Level 6

Screen Shot 2020-11-11 at 7.54.11 PM.pngScreen Shot 2020-11-11 at 7.54.42 PM.png

Ksharp
Super User
data have;
call streaminit(123);
do i=1 to 100;
x=rand('uniform')*6;
y=rand('uniform')*6;
output;
end;
run;

proc sgplot data=have;
scatter x=x y=y;
xaxis values=(1 to 7 by 1);
yaxis values=(1 to 7 by 1);
run;
Aerianna9
Fluorite | Level 6
This was helpful for the grid. Now I'm needing help with the point count for each grid cell. Any ideas?
ballardw
Super User

@Aerianna9 wrote:
This was helpful for the grid. Now I'm needing help with the point count for each grid cell. Any ideas?

One way is to create a custom format for each range of value with the desired boundaries for cells. Then apply that format in procedure to count things.

 

An example using @Ksharp's example data set modified to create "nicer" cell boundaries:

data have;
call streaminit(123);
do i=1 to 100;
x=rand('uniform')*7;
y=rand('uniform')*7;
output;
end;
run;
proc format; value xcell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; value ycell 0 -<1 = '1' 1 -<2 = '2' 2 -<3 = '3' 3 -<4 = '4' 4 -<5 = '5' 5 -<6 = '6' 6 -<7 = '7' ; run; proc sort data=have; by descending y; run; proc tabulate data=have; class x; class y/ order=data; format x xcell. y ycell.; table y, x *n=' ' / misstext='0' ; run;

The 7 x 7 cell boundaries were relatively easy due to the way the data set was made so each variable has values in the [0,7] range. In a more typical fashion you would need to do more work with the formats (and your actual data). This relatively easily is made to match a VALUES option on a graph axis statement.

 

The sort was so the cell count orientation would match the graph closer.

Aerianna9
Fluorite | Level 6
Thank you so very much, you've been a great help!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2596 views
  • 6 likes
  • 3 in conversation