Hello, pals
CAS does not support the R library circlize. Codes:
proc iml;
run ExportDataSetToR("WORK.chord_1", "RCBD_IN_R");
submit / R;
library(circlize)
values <- c(2, 0, 0, 3, 7, 1, 29, 1, 22, 15, 0, 3, 0, 0, 1, 1, 18, 0, 15, 5, 1, 15, 0, 10, 9)
matrix <- matrix(values, 5, 5) # a matrix with 5 rows and 5 columns
matrix2 <- t(matrix)
print(matrix)
print(matrix2)
rownames(matrix2) <- c("Day 4 Danger", "Day 4 Optimal", "Day 4 Over", "Day 4 Suboptimal", "Day 4 Under")
colnames(matrix2) <- c("Day 7 Danger", "Day 7 Optimal", "Day 7 Over", "Day 7 Suboptimal", "Day 7 Under")
colors <- c("Day 4 Danger" = "Red", "Day 4 Optimal" = "#008000", "Day 4 Over" = "Orange", "Day 4 Suboptimal" = "#318ce7", "Day 4 Under" = "Yellow", "Day 7 Danger" = "#ff033e", "Day 7 Optimal" = "#a4c639", "Day 7 Over" = "#ffbf00", "Day 7 Suboptimal" = "#5d8aa8", "Day 7 Under" = "#e9d66b")
chordDiagram(matrix2, grid.col = colors, transparency = 0.6);
endsubmit;
quit;
Logs:
ERROR: R: Error in library(circlize) : there is no package called ‘circlize’
Can we import the library in the SAS Viya CAS? Thanks.
@TomHsiung wrote:
I access SAS Viya for learners and I believe I cannot modify the R_Home environment.
Home > SAS Communities Library >
Which Open-Source Packages are included in SAS Viya for Learners?
Last update: 03-23-2023
Updated by: SAS Employee Academic_Lori
Koen
if you use PROC IML in SAS Viya, then you are submitting on the compute server (aka SPRE = SAS Programming Runtime Environment), not on CAS.
In PROC CAS, you can load and call the IML action set, but I believe the IML action set does not allow for a "submit / R" block.
Anyway , you get this ERROR.
ERROR: R: Error in library(circlize) : there is no package called ‘circlize’
Essentially I believe that the reason why you cannot load a package like ‘circlize’, is that your R_Home environment variable is pointing to an old installation where the ‘circlize’-package is not installed. After you update your R_Home environment variable to your most recent version of R that includes ‘circlize’, please try loading the library again in PROC IML.
By the way ... I am moving your question to the appropriate board (SAS/IML - board).
Koen
@TomHsiung wrote:
I access SAS Viya for learners and I believe I cannot modify the R_Home environment.
Home > SAS Communities Library >
Which Open-Source Packages are included in SAS Viya for Learners?
Last update: 03-23-2023
Updated by: SAS Employee Academic_Lori
Koen
Thank you very much and it works. Although by default the package of circlize is not installed, I just built it up. Great!
Regards,
Tom
Update:
I can install and use the circlize library in JupyterLab R console. But when I tried to do the same in JupyterLab SAS console, I got errors.
WARNING: R: Warning in install.packages("circlize") : WARNING: R: 'lib = "/opt/sas/viya/home/sas-pyconfig/R-4.2.2.1717422377/lib64/R/library"' is not writable ERROR: R: Error in askYesNo(gettext("Would you like to use a personal library instead?"), : ERROR: R: Unrecognized response “library(circlize)”
Output from JupyterLab R console:
Codes in JupyterLab SAS console:
proc iml;
submit / R;
Sys.setenv(R_LIBS_USER="/opt/conda/lib/R/library")
install.packages("circlize")
library(circlize)
# Input matrix
values <- c(
1,0,0,2,0,
1,0,1,1,0,
1,0,0,0,0,
1,0,0,0,0,
4,0,3,4,0,
7,2,4,10,0,
2,0,0,0,0,
1,0,1,1,1,
1,0,0,0,0,
7,0,10,15,0,
0,0,0,1,0,
1,0,0,0,0,
1,0,0,1,0,
4,0,1,6,0,
4,0,0,4,0,
1,0,0,1,0,
1,0,0,2,0,
0,0,0,1,0,
1,0,0,2,0,
11,1,36,33,6
)
matrix <- matrix(values, 5, 20)
# Labeling
rownames(matrix) <- c("Age 65 to 80", "Over 80", "Age 30 to 50", "Age 50 to 65", "Less than 30") # Label the row categories
colnames(matrix) <- c("Atrial fibrillation", "AF, DM", "AF, DM, HF", "AF, DM, HF, HTN", "AF, HF", "AF, HF, HTN", "AF, HF, Stroke", "AF, HTN",
"AF, HTN, Stroke", "AF, Stroke", "Diabetes", "DM, HF, HTN", "DM, HTN", "DM, HTN, Stroke", "Heart failure", "HF, HTN", "Hypertension",
"HTN, Stroke", "No comorbidity", "Stroke") # Label the column categories
# Define colors
colors <- c("Over 80" = "Red", "Age 50 to 65" = "#008000", "Age 30 to 50" = "Orange", "Age 65 to 80" = "#ffef00", "Less 30" = "#2a52be", "No comorbidity" = "black", "Atrial fibrillation" = "#ff0800", "Diabetes" = "#a52a2a", "Hypertension" = "#ffbcd9")
# Generate the chord diagram
# chordDiagram(matrix, transparency = 0.6, annotationTrack = c("axis", "grid")) # Make the chord diagram
circos.par(canvas.xlim = c(-0.80, 0.80), canvas.ylim = c(-0.80, 0.80))
chordDiagram(matrix, grid.col = colors, scale = FALSE, annotationTrack = c("grid", "axis"),
preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(matrix))))))
circos.track(track.index = 1, panel.fun = function(x, y) {
circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,
facing = "clockwise", niceFacing = TRUE, adj = c(-0.30, 0), cex = 0.50)
}, bg.border = NA) # here set bg.border to NA is important
title(main = "Figure 1 Relationship between age categories and comorbidities", font.main = 1)
endsubmit;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.