Hi.
I want to assign different colors to my violinplot, but cant figure out how to. The styleatrrs is not working for me. Below my code. I want to make different colors for the plot based on value in RG (horisontal panel).
Ideally also a lighter shade in præpost_kat (vertical panel) depending on value. But that is not as important
proc sgpanel data=plot;
where rg in (0,1);
panelby rg præpost_kat / layout=lattice onepanel novarname noborder colheaderpos=bottom;
band y=tils upper=density lower=mirror / fill outline;
format rg rgx. præpost_kat bean_katx.;
colaxis display=none;
rowaxis label='TILs' grid;
run;
Its getting me this. Which I want. But I cant change the colors, and google cant help me.
thank you in advance
Good thing you caught a fellow dane then 🙂
I made a few changes to your code and inserted an attribute map to control the colors.
Feel free to ask if you have any questions.
data sorted;
input TILs prepost_kat rg;
datalines;
1 1 0
5 1 0
20 1 0
5 1 0
10 1 0
5 1 0
0 1 0
10 1 0
0 1 0
50 1 0
10 1 0
20 1 0
10 1 0
10 1 0
5 1 0
5 1 0
10 1 0
5 1 0
10 1 0
0 1 0
0 1 0
0 1 0
0 1 0
30 1 0
1 1 0
20 1 0
5 1 0
10 1 0
5 1 0
1 1 0
0 1 0
5 1 0
0 1 0
30 1 0
20 1 0
10 1 0
5 1 0
5 1 0
1 1 0
0 1 0
5 1 0
20 1 0
5 1 0
20 1 0
1 2 0
5 2 0
5 2 0
20 2 0
50 2 0
0 2 0
1 2 0
30 2 0
20 2 0
80 2 0
70 2 0
40 2 0
5 2 0
30 2 0
20 2 0
30 2 0
5 2 0
50 2 0
10 2 0
10 2 0
1 2 0
0 2 0
20 2 0
30 2 0
10 2 0
30 2 0
40 2 0
20 2 0
5 2 0
10 2 0
0 2 0
1 2 0
5 2 0
5 2 0
20 2 0
30 2 0
30 2 0
30 2 0
20 2 0
0 2 0
1 2 0
20 2 0
5 2 0
40 2 0
40 1 1
0 1 1
5 1 1
20 1 1
30 1 1
10 1 1
1 1 1
5 1 1
5 1 1
50 1 1
1 1 1
1 1 1
5 1 1
10 1 1
1 1 1
20 1 1
5 1 1
10 1 1
5 1 1
40 1 1
1 1 1
10 1 1
20 1 1
5 1 1
10 1 1
0 1 1
1 1 1
30 1 1
30 1 1
20 1 1
10 1 1
5 1 1
0 1 1
10 1 1
5 1 1
5 1 1
20 1 1
10 1 1
5 1 1
30 1 1
5 1 1
5 1 1
5 1 1
5 1 1
1 1 1
0 1 1
1 1 1
20 1 1
5 1 1
0 1 1
0 1 1
30 1 1
0 1 1
0 1 1
1 1 1
10 1 1
20 1 1
30 1 1
1 2 1
5 2 1
20 2 1
1 2 1
5 2 1
10 2 1
5 2 1
5 2 1
30 2 1
50 2 1
30 2 1
5 2 1
5 2 1
30 2 1
5 2 1
20 2 1
5 2 1
5 2 1
10 2 1
20 2 1
30 2 1
5 2 1
50 2 1
40 2 1
10 2 1
30 2 1
5 2 1
5 2 1
20 2 1
30 2 1
30 2 1
10 2 1
20 2 1
20 2 1
20 2 1
10 2 1
10 2 1
30 2 1
10 2 1
5 2 1
10 2 1
0 2 1
5 2 1
1 2 1
10 2 1
0 2 1
10 2 1
20 2 1
5 2 1
10 2 1
5 2 1
20 2 1
1 2 1
1 2 1
5 2 1
15 2 1
10 2 1
30 2 1
;
proc kde data=sorted;
by rg prepost_kat;
univar tils / plots=none out=tils_dens (rename=(value=tils));
run;
data plot;
set tils_dens;
by prepost_kat notsorted;
mirror=-density;
if first.prepost_kat then group+1;
run;
data myattrmap;
input ID $ value linecolor $ fillcolor $;
datalines;
myid 1 blue blue
myid 2 green green
myid 3 red red
myid 4 gold gold
;
proc sgpanel data=plot dattrmap=myattrmap noautolegend;
where rg in (0,1);
panelby rg prepost_kat / layout=lattice onepanel novarname noborder colheaderpos=bottom;
band y=tils upper=density lower=mirror / group=group fill outline;
format rg rgx. prepost_kat bean_katx.;
colaxis display=none;
rowaxis label='TILs' grid;
run;
Result:
Are you able to post your data or a sample of it for testing?
Up to you 🙂
So I have some of the data here. It is data=sorted
But I saved it in excel and changed the name so I didnt use æ with is specifik to Denmark 🙂
and then I hade this code, before the code I posted at the first post.
proc kde data=sorted;
by rg 'præpost_kat'n;
univar tils / plots=none out=tils_dens (rename=(value=tils));
run;
data plot;
set tils_dens;
mirror=-density;
run;
Good thing you caught a fellow dane then 🙂
I made a few changes to your code and inserted an attribute map to control the colors.
Feel free to ask if you have any questions.
data sorted;
input TILs prepost_kat rg;
datalines;
1 1 0
5 1 0
20 1 0
5 1 0
10 1 0
5 1 0
0 1 0
10 1 0
0 1 0
50 1 0
10 1 0
20 1 0
10 1 0
10 1 0
5 1 0
5 1 0
10 1 0
5 1 0
10 1 0
0 1 0
0 1 0
0 1 0
0 1 0
30 1 0
1 1 0
20 1 0
5 1 0
10 1 0
5 1 0
1 1 0
0 1 0
5 1 0
0 1 0
30 1 0
20 1 0
10 1 0
5 1 0
5 1 0
1 1 0
0 1 0
5 1 0
20 1 0
5 1 0
20 1 0
1 2 0
5 2 0
5 2 0
20 2 0
50 2 0
0 2 0
1 2 0
30 2 0
20 2 0
80 2 0
70 2 0
40 2 0
5 2 0
30 2 0
20 2 0
30 2 0
5 2 0
50 2 0
10 2 0
10 2 0
1 2 0
0 2 0
20 2 0
30 2 0
10 2 0
30 2 0
40 2 0
20 2 0
5 2 0
10 2 0
0 2 0
1 2 0
5 2 0
5 2 0
20 2 0
30 2 0
30 2 0
30 2 0
20 2 0
0 2 0
1 2 0
20 2 0
5 2 0
40 2 0
40 1 1
0 1 1
5 1 1
20 1 1
30 1 1
10 1 1
1 1 1
5 1 1
5 1 1
50 1 1
1 1 1
1 1 1
5 1 1
10 1 1
1 1 1
20 1 1
5 1 1
10 1 1
5 1 1
40 1 1
1 1 1
10 1 1
20 1 1
5 1 1
10 1 1
0 1 1
1 1 1
30 1 1
30 1 1
20 1 1
10 1 1
5 1 1
0 1 1
10 1 1
5 1 1
5 1 1
20 1 1
10 1 1
5 1 1
30 1 1
5 1 1
5 1 1
5 1 1
5 1 1
1 1 1
0 1 1
1 1 1
20 1 1
5 1 1
0 1 1
0 1 1
30 1 1
0 1 1
0 1 1
1 1 1
10 1 1
20 1 1
30 1 1
1 2 1
5 2 1
20 2 1
1 2 1
5 2 1
10 2 1
5 2 1
5 2 1
30 2 1
50 2 1
30 2 1
5 2 1
5 2 1
30 2 1
5 2 1
20 2 1
5 2 1
5 2 1
10 2 1
20 2 1
30 2 1
5 2 1
50 2 1
40 2 1
10 2 1
30 2 1
5 2 1
5 2 1
20 2 1
30 2 1
30 2 1
10 2 1
20 2 1
20 2 1
20 2 1
10 2 1
10 2 1
30 2 1
10 2 1
5 2 1
10 2 1
0 2 1
5 2 1
1 2 1
10 2 1
0 2 1
10 2 1
20 2 1
5 2 1
10 2 1
5 2 1
20 2 1
1 2 1
1 2 1
5 2 1
15 2 1
10 2 1
30 2 1
;
proc kde data=sorted;
by rg prepost_kat;
univar tils / plots=none out=tils_dens (rename=(value=tils));
run;
data plot;
set tils_dens;
by prepost_kat notsorted;
mirror=-density;
if first.prepost_kat then group+1;
run;
data myattrmap;
input ID $ value linecolor $ fillcolor $;
datalines;
myid 1 blue blue
myid 2 green green
myid 3 red red
myid 4 gold gold
;
proc sgpanel data=plot dattrmap=myattrmap noautolegend;
where rg in (0,1);
panelby rg prepost_kat / layout=lattice onepanel novarname noborder colheaderpos=bottom;
band y=tils upper=density lower=mirror / group=group fill outline;
format rg rgx. prepost_kat bean_katx.;
colaxis display=none;
rowaxis label='TILs' grid;
run;
Result:
Anytime 🙂
@Signesk wrote:
follow up question.
I want to make the blue and red the same color and the green and gold as well
I tried changing your code like this
data myattrmap;
input ID $ value linecolor $ fillcolor $;
datalines;
myid 1 blue blue
myid 2 green green
myid 3 blue blue
myid 4 green green
;
But it remains in the four original colors.
Add the option :
attrid=myid
to the BAND statement options.
band y=tils upper=density lower=mirror / group=group fill outline attrid=myid;
Follow up question number two!
When I publish it as pdf/png or just copy it into powerpoint and enlarge it a new problem arises. The figure in the right top corner remains fine, but the three others seems to have a dotted line around them, I haven't changed anything in the code.
data myattrmap;
input ID $ value linecolor $ fillcolor $;
datalines;
myid 1 CXCD5C5C CXCD5C5C
myid 2 cx880000 cx880000
myid 3 CXCD5C5C CXCD5C5C
myid 4 cx880000 cx880000
;
proc sgpanel data=plot dattrmap=myattrmap noautolegend;
where rg in (0,1);
panelby rg prepost_kat / layout=lattice onepanel novarname noborder colheaderpos=bottom;
band y=tils upper=density lower=mirror / group=group fill outline attrid=myid;
format rg rgx. prepost_kat katx.;
colaxis display=none;
rowaxis label='TILs %' grid;
run;
I tried changing the linecolor to black and it very well illustrates the problem
data myattrmap;
input ID $ value linecolor $ fillcolor $;
datalines;
myid 1 black CXCD5C5C
myid 2 black cx880000
myid 3 CXCD5C5C CXCD5C5C
myid 4 cx880000 cx880000
;
So I want the linecolor to be solid. Thank you in advance
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.