-1

我在 SAS 中使用 ODS 和 SGPLOT 制作了图形,我的代码如下所示:

ods rtf file="D:\" style=journal bodytitle nogfootnote;
goptions reset=all;
ods graphics / border=off width=18cm height=8cm ;
ods graphics / border=off width=17cm height=8.5cm;

footnote1 "Program: ";

PROC SGPLOT data=data  noautolegend;
...
keylegend / title="Group:";

run;

ods rtf close;

我正在使用颜色,但输出的 .rtf 文件是黑白的,我怎样才能使它着色?

4

2 回答 2

1

样式中的颜色定义journal是灰色阴影。

使用不同的风格。 STYLE=RTF可能没问题。

filename myrtf "%sysfunc(pathname(work))\workers.rtf";

ods rtf file=myrtf style=rtf bodytitle nogfootnote;
goptions reset=all;
ods graphics / border=off width=18cm height=8cm ;
ods graphics / border=off width=17cm height=8.5cm;

footnote1 "Program: ";

PROC SGPLOT data=sashelp.workers  noautolegend;
  series x=date y=electric;
  series x=date y=masonry;
run;

ods rtf close;

您可以浏览样式源:

  • 交互式
    • 右键单击结果树的根 →​​ 模板 → Sashelp.TmplMst → 样式 → 日记
  • 以编程方式

    proc template;
      source styles.journal;
    run;
    

LOG 将显示所有图形颜色定义

define style Styles.Journal;
   parent = styles.default;
   . . .    
   class GraphColors /
      'goffill' = cx666666
      'gofill' = cxf6f6f6
      'govbline' = cx848b93
      'gobline' = cx848b93
      'gncdata12' = cx000000
      'gncdata11' = cx000000
      'gncdata10' = cx000000
      'gncdata9' = cx000000
      'gncdata8' = cx000000
      'gncdata7' = cx000000
      'gncdata6' = cx000000
      'gncdata5' = cx000000
      'gncdata4' = cx000000
      'gncdata3' = cx000000
      'gncdata2' = cx000000
      'gncdata1' = cx000000
      'gncdata' = cx000000
      'gndata12' = cx8F8F8F
      'gndata11' = cxF1F1F1
      'gndata10' = cxABABAB
      'gndata9' = cxBDBDBD
      'gndata8' = cxCFCFCF
      'gndata7' = cxD9D9D9
      'gndata6' = cx989898
      'gndata5' = cxE9E9E9
      'gndata4' = cxA1A1A1
      'gndata3' = cxB4B4B4
      'gndata2' = cxC6C6C6
      'gndata1' = cxE2E2E2
      'gndata' = cxE2E2E2
      'gnclink' = cx969696
      'gnlink' = cxC4C4C4
      'gntext' = cx111111
      'gblockheader' = cxd4d4d4
      'gcphasebox' = cx000000
      'gphasebox' = cxBBBBBB
      'gczonec' = cxC9C9C9
      'gzonec' = cxD8D8D8
      'gczoneb' = cxD8D8D8
      'gzoneb' = cxE1E1E1
      'gzonea' = cxEBEBEB
      'gcunder' = cxCCCCCC
      'gunder' = cxCCCCCC
      'gcover' = cxF1F1F1
      'gover' = cxF1F1F1
      'gcfinal' = cx777777
      'gfinal' = cx777777
      'gcinitial' = cx222222
      'ginitial' = cx222222
      'gcother' = cxF1F1F1
      'gother' = cxF1F1F1
      'gcmiss' = cx545454
      'gmiss' = cx000000
      'gablock' = cxE0E0E0
      'gblock' = cxF2F2F2
      'gcclipping' = cx000000
      'gclipping' = cxD2D2D2
      'gcstars' = cx000000
      'gstars' = cxD2D2D2
      'gcruntest' = cxA3A3A3
      'gruntest' = cxDDDDDD
      'gccontrollim' = cxC2C2C2
      'gcontrollim' = cxF0F0F0
      'gcerror' = cx000000
      'gerror' = cxA0A0A0
      'gcpredictlim' = cx000000
      'gpredictlim' = cxC8C8C8
      'gcpredict' = cx000000
      'gpredict' = cx000000
      'gcconfidence2' = cx000000
      'gcconfidence' = cx000000
      'gconfidence2' = cxA8A8A8
      'gconfidence' = cxC8C8C8
      'gcfit2' = cx000000
      'gcfit' = cx000000
      'gfit2' = cx000000
      'gfit' = cx000000
      'gcoutlier' = cx000000
      'goutlier' = cxA0A0A0
      'gcdata' = cx000000
      'gdata' = cxD2D2D2
      'ginsetheader' = colors('docbg')
      'ginset' = cxFFFFFF
      'greferencelines' = cx808080
      'gheader' = colors('docbg')
      'gramp3cend' = cx5F5F5F
      'gramp3cneutral' = cxA7A7A7
      'gramp3cstart' = cxF0F0F0
      'gramp2cend' = cx5F5F5F
      'gramp2cstart' = cxF0F0F0
      'gconramp3cend' = cx000000
      'gconramp3cneutral' = cx777777
      'gconramp3cstart' = cxC4C4C4
      'gconramp2cend' = cx5F5F5F
      'gconramp2cstart' = cxF0F0F0
      'gtext' = cx000000
      'glabel' = cx000000
      'gborderlines' = cx000000
      'goutlines' = cx000000
      'gmgrid' = cxF2F2F2
      'ggrid' = cxECECEC
      'gaxis' = cx000000
      'gshadow' = cx000000
      'glegend' = cxFFFFFF
      'gfloor' = cxCCCCCC
      'gwalls' = cxFFFFFF
      'gckran5' = cx000000
      'gkran5' = cxe1e1e1
      'gckran4' = cx000000
      'gkran4' = cxbfbfbf
      'gckran3' = cx000000
      'gkran3' = cx828282
      'gckran2' = cx000000
      'gkran2' = cx454545
      'gckran1' = cx000000
      'gkran1' = cx080808
      'gcdata12' = cx000000
      'gcdata11' = cx000000
      'gcdata10' = cx000000
      'gcdata9' = cx000000
      'gcdata8' = cx000000
      'gcdata7' = cx000000
      'gcdata6' = cx000000
      'gcdata5' = cx000000
      'gcdata4' = cx000000
      'gcdata3' = cx000000
      'gcdata2' = cx000000
      'gcdata1' = cx000000
      'gdata11' = CXe1e1e1
      'gdata5' = CXcfcfcf
      'gdata1' = CXbfbfbf
      'gdata7' = CXababab
      'gdata8' = CX969696
      'gdata2' = CX828282
      'gdata9' = CX6e6e6e
      'gdata3' = CX595959
      'gdata10' = CX454545
      'gdata4' = CX303030
      'gdata6' = CX1c1c1c
      'gdata12' = CX080808;
于 2018-05-24T13:58:03.797 回答
0

您的代码中没有任何内容表明图表应该有颜色。如果您在 PROC SGPLOT 中指定颜色,它们将被尊重并覆盖样式。您选择的 STYLE 是 Journal,它是为印刷期刊(亿万年前)设计的,不包括设计颜色。

这显示了差异,其中第一个图表带有颜色,而第二个图表没有颜色,并采用 Journal 的默认样式。

正如另一位用户指出的那样,您可以选择不同的样式并获得自动颜色,但它们是模板颜色,而不是您选择的颜色。在 SGPLOT 中指定颜色有多种方法,这里使用的方法有点矫枉过正,但它的文档示例非常易于使用和复制/粘贴。这是一种通常用于确保项目在多个图表中的颜色相似的方法,即使在可能缺少值的情况下也是如此,因为 SAS 会按顺序循环颜色,而不管组/缺失如何。

data fruit_sales;
input Fruit $ Sales;
datalines;
Apples   40
Pears    25
Oranges  50
Grapes   30
Bananas  60
run;

data attrmapfruit;
retain linecolor "black";
input id $ value $ fillcolor $;
datalines;
fruit Apples  red
fruit Pears   green
fruit Oranges orange
fruit Grapes  purple
fruit Bananas yellow
;
run;


ods rtf file='/folders/myfolders/demo.rtf' style=journal;

title  "Fruit Sales V01 - color";
proc sgplot data=fruit_sales dattrmap=attrmapfruit;
vbar Fruit / response=Sales group=Fruit attrid=fruit;
run;
title;

title  "Fruit Sales V02 - no formats";
proc sgplot data=fruit_sales;
vbar Fruit / response=Sales group=Fruit ;
run;
title;

ods rtf close;
于 2018-05-25T00:39:44.560 回答