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

## Scatterplot Help!

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

Aerianna

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Scatterplot Help!

@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.

7 REPLIES 7
Super User

## Re: Scatterplot Help!

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.

Fluorite | Level 6

## Re: Scatterplot Help!

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

Super User

## Re: Scatterplot Help!

``````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;``````
Fluorite | Level 6

## Re: Scatterplot Help!

This was helpful for the grid. Now I'm needing help with the point count for each grid cell. Any ideas?
Super User

## Re: Scatterplot Help!

@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.

Fluorite | Level 6

## Re: Scatterplot Help!

Thank you so very much, you've been a great help!
Discussion stats
• 7 replies
• 2596 views
• 6 likes
• 3 in conversation