SAS SGPlot scatterplot选项 - 按属性分组

时间:2014-05-29 12:40:51

标签: sas scatter-plot

我对SAS中的SGPlot有两个问题。我有一个大型数据集,我正在尝试创建一个散点图,突出了类似产品品牌之间的差异。我能够为每个品牌获得不同的颜色,但由于某种原因,符号不会出现。我不得不关闭ods列表和html因为我收到错误错误:无法将图像写入filename.png。请确保设置了正确的磁盘权限。我不确定这是否可以修复。是否有另一种获取符号的方法?

另外,我有一个95%的预测椭圆,但我想知道是否有办法让每个品牌都有一个椭圆。感谢。

data example;
    length product brand $20;
    input product $ brand $ item price trans;
cards;
sconces AllenRoth 1 1.5 300
sconces AllenRoth 2 2.75 350
sconces AllenRoth 3 1.75 300
sconces AllenRoth 4 0.75 400
sconces GardenTreasures 1 3 200
sconces GardenTreasures 2 3.25 175
sconces GardenTreasures 3 2.75 100
sconces GardenTreasures 4 3.5 100
sconces GardenTreasures 5 4 150
sconces OtherBrand 1 0.5 850
sconces OtherBrand 2 0.45 875
sconces OtherBrand 3 0.75 900
sconces OtherBrand 4 1 650
sconces OtherBrand 5 0.75 700
sconces BrandX 1 1 200
sconces BrandX 2 1.25 500
sconces BrandX 3 1.2 400
sconces BrandX 4 0.95 375
sconces BrandX 5 1 300
sconces BrandX 6 1 200
sconces BrandX 7 1.35 400
sconces BrandX 8 1.5 350
curtains AllenRoth 1 10 200
curtains AllenRoth 2 12 250
curtains AllenRoth 3 11.5 200
curtains AllenRoth 4 10 400
curtains AllenRoth 5 17 500
curtains AllenRoth 6 15 100
curtains AllenRoth 7 29 50
curtains AllenRoth 8 50 12
curtains GardenTreasures 1 80 150
curtains GardenTreasures 2 60 75
curtains GardenTreasures 3 100 50
curtains BrandX 1 9 300
curtains BrandX 2 12 350
curtains BrandX 3 10 275
curtains BrandX 4 7.5 400
curtains BrandX 5 12 200
curtains BrandX 6 8.5 500
; 
run;

proc format;
    value legfmt
    1 = 'legend value 1'
    2 = 'legend value 2'
    3 = 'legend value 3'
    4 = 'legend value 4';
run;

proc sort data= example;
    by product brand;
run;

ods listing close;
ods html close;

proc sgplot data= example ;
    title1 "plotting trans by price";
    footnote1 "final";
    by product;
    scatter x= trans y= price / datalabel= item group= brand name= "scp";
    ellipse x=trans y=price;
    xaxis label= "Number of Transactions";
    yaxis label= "Average Selling Price";
    keylegend "scp" / noborder across= 1 down= 4 location= outside position= topright
    title= "Legend";
run;

ods graphics off;
ods listing close;

1 个答案:

答案 0 :(得分:1)

可能你的gpath没有正确设置。这对我有用,例如:

ods html path='c:\temp' file='test.html' gpath='c:\temp\' style=htmlblue;
proc sgplot data= example ;
    title1 "plotting trans by price";
    footnote1 "final";
    by product;
    scatter x= trans y= price / datalabel= item group= brand name= "scp";
    ellipse x=trans y=price;
    xaxis label= "Number of Transactions";
    yaxis label= "Average Selling Price";
    keylegend "scp" / noborder across= 1 down= 4 location= outside position= topright
    title= "Legend";
run;
ods html close;

如果您没有将gpath设置为您可以写入的路径,则可能会将其设置为您没有写入权限的内容,尤其是在您安装了服务器的情况下。 PATH和GPATH可以设置为相同或不同的路径。

我不相信你可以为每个品牌设一个椭圆形,主要是因为它看起来很糟糕。具有四个预测椭圆,即使具有不同的颜色,也很难在视觉上区分。如果您要尝试显示(可能是条形图,例如以brand作为条形类型并将销售价格桶作为组变量,则可能适用不同的图表类型)。