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

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


bean.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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:

 

 

Udklip.PNG

View solution in original post

11 REPLIES 11
PeterClemmensen
Tourmaline | Level 20

Are you able to post your data or a sample of it for testing?

Signesk
Fluorite | Level 6
I will have to check sine it is patient data. And do I just type it in below in colums or attach as a sasdatafile?
PeterClemmensen
Tourmaline | Level 20

Up to you 🙂

Signesk
Fluorite | Level 6

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;

 

 

PeterClemmensen
Tourmaline | Level 20

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:

 

 

Udklip.PNG

Signesk
Fluorite | Level 6
Thank you so much. This is exactly it!
Signesk
Fluorite | Level 6
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.
ballardw
Super User

@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;
Signesk
Fluorite | Level 6
Thank you! Problem solved
Signesk
Fluorite | Level 6

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;

 

beanplot tils.png

 

 

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
;

 

tilsbal.png

 

So I want the linecolor to be solid. Thank you in advance

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 11 replies
  • 1209 views
  • 2 likes
  • 3 in conversation