I have 'Error in normalizePath' in visNetwork R - r

I'm trying to generate a graph with the VisNetwork package of R. But I got the error
Error in normalizePath(target_dir, "/", TRUE) :
path[1]="query/htmlwidgets-1.2": No such file or directory
The code I've written is :
visNetwork(nodes = nodes, edges = edges, width = "100%", height = 900,
main = list(
style = 'font:caption;font-weight:bold;font-size:15px;text-align:center;')) %>%
visPhysics(solver = "forceAtlas2Based",
stabilization = T,
timestep=0.25,
forceAtlas2Based = list(gravitationalConstant = -50, avoidOverlap = 0.95)) %>%
visOptions(highlightNearest = TRUE) %>%
visEdges(smooth = T) %>%
visNodes(scaling = list(min = 10, max = 40))%>%
visSave(file = save_name, background = "white",selfcontained = T)
}
The error appears when I set save_name to any directory different from './' .
But what is more Surprising is that I can't find the generated file anywhere.
Can anyone help me to solve this so I can set the path I want ?
Thanks

Related

Rayshader package error for Plotting and Saving 2D and 3D Visualizations in R studio

For 3D visualizaiton used matrix data. Package: Rayshader 0.34.0.
The data is can be seen in render_camera but using high_quality function facing problem in saving rendeeing out put.
Error in rayrender::obj_model(cache_filename, x = -bbox_center[1], y = -bbox_center[2], :
unused argument (texture = TRUE)
I was expecting a render image so that my 3d map can be saved in png format with rendering quality.
mat |>
height_shade(texture = textr) |>
plot_3d(heightmap = mat,
zscale = 1000,
solid = FALSE,
shadowdepth = 0)
render_camera(theta = -100, phi = 30, zoom = .7)
render_highquality("E:/URP/R/3D Bangladesh/DATA/Images/tp.png",
samples = 450,
preview = FALSE,
light = TRUE,
lightdirection = c(135, 45),
lightcolor = c("white"),
lightintensity = c(800),
ambient_light = 0.5,
shadow_intensity = 0.5,
zscale = 1,
width = 8000, height = 8000,
interactive = FALSE)
Install most recent dev versions of rayshader and rayrender.
remotes::install_github("https://github.com/tylermorganwall/rayshader")
remotes::install_github("https://github.com/tylermorganwall/rayrender")
Same issue.
I've tried to install the most recent dev versions but probably I do something wrong.
What do I have to choose here (and later similarly for rayrender)?
terminal options
If I choose "All" at every steps I get some conflicts

How do you call internal functions?

I'm working on a script given to me and was given the following error:
Error in get_rows_id(x[[part]], i) :
invalid row selection: out of range selection
I tried searching for the get_rows_id function within the script but couldn't find it. So I ran list.files on all the packages to see where it was coming from and realized it was from the flextable package:
list.files(system.file(package = 'flextable'), recursive = T, full.names = T))
I didn't see anything using browser where flextable was used.
Is there another way non-exported functions can be called or hidden within another function in the script?
The only other way I have found to run an internal function would be
flextable:::get_rows_id
but that's a direct way I don't see in the script.
Here's the portion with flextable:
df %>%
# opts
flextable(cheight = cell_height) %>%
add_footer_lines(top = F, values = source_caption(report_quarter)) %>%
style(pr_p = def_par, pr_t = def_text, pr_c = def_cell, part = "all") %>%
style(pr_c = def_header_bg,
pr_t = def_text_header,
part = "header") %>%
style(j = 1, pr_p = update(text.align = "left", def_par),
part = "body") %>%
style(pr_p = update(text.align = "left", def_par),
pr_c = update(vertical.align = "bottom", border.bottom = fp_border(width = 0), def_cell),
pr_t = update(color = cbre_pal[2], def_text),
part = "footer") %>%
style(i = which(submarket_order %in% totals),
j = 1,
pr_t = update(bold = T, def_text)) %>%
## Row borders
border(border.top = body_border, border.bottom = body_border,
part = "body") %>%
width(width = cell_width) %>%
width(j = 1, 1.55) %>%
height(height = .28, part = "header") %>% # changed from .65
void(1, part = "header")
I wasn't able to figure out how to call the internal function other than flextable:::get_rows_id. However, I was able to solve the issue by place browser () in one of my other functions that called my df. Turns out the bug was further up in the call sequence. If you're in the same boat your best bet is to just look at everything that's interacting with said function. Hope I was able to help, good luck.

Remove vertex.tooltips from ndtv d3movie

I'm plotting a dynamic network visulisation using the Statnet, networkd3, and ndtv packages.
In the vignette for this package, the authors explain how to "generate interactive html tooltips to be displayed when the vertices are clicked on":
render.d3movie(
toy_epi_sim,
render.par = render.par,
plot.par = plot.par,
vertex.cex = 0.9,
vertex.col = "ndtvcol",
edge.col = "darkgrey",
vertex.border = "lightgrey",
displaylabels = FALSE,
vertex.tooltip = function(slice){paste('name:',slice%v%'vertex.names','<br>',
'status:', slice%v%'testatus')},
output.mode='htmlWidget')
However, I'd like to remove these tooltips, since by default they just show meaningless node IDs, and I'm already showing node labels instead.
Things like vertex.tooltip = F or vertex.tooltip = NA don't work - how do I turn off vertex tooltips?
This is the code I'm using:
render.d3movie(net, usearrows = T, label = "gmv_label",
displaylabels = T,
bg="#ffffff",
edge.col = "#ff0063",
vertex.col = "colo",
vertex.cex = "amount",
edge.lwd = 5,
launchBrowser=T, filename= XXX,
render.par=list(tween.frames = 30, show.time = F),
plot.par=list(mar=c(0,0,0,0)))

Heatmap of Gene intensity values in R

I have data that look like this:
Gene
HBEC-KT-01
HBEC-KT-02
HBEC-KT-03
HBEC-KT-04
HBEC-KT-05
Primarycells-02
Primarycells-03
Primarycells-04
Primarycells-05
BPIFB1
15726000000
15294000000
15294000000
14741000000
22427000000
87308000000
2.00E+11
1.04E+11
1.51E+11
LCN2
18040000000
26444000000
28869000000
30337000000
10966000000
62388000000
54007000000
56797000000
38414000000
C3
2.52E+11
2.26E+11
1.80E+11
1.80E+11
1.78E+11
46480000000
1.16E+11
69398000000
78766000000
MUC5AC
15647000
8353200
12617000
12221000
29908000
40893000000
79830000000
28130000000
69147000000
MUC5B
965190000
693910000
779970000
716110000
1479700000
38979000000
90175000000
41764000000
50535000000
ANXA2
14705000000
18721000000
21592000000
18904000000
22657000000
28163000000
24282000000
21708000000
16528000000
I want to make a heatmap like the following using R. I am following a paper and they quoted "Heat maps were generated with the ‘pheatmap’ package76, where correlation clustering distance row was applied". Here is their heatmap.
I want the same like this and I am trying to make one using R by following tutorials but I am new to R language and know nothing about R.
Here is my code.
df <- read.delim("R.txt", header=T, row.names="Gene")
df_matrix <- data.matrix(df)
pheatmap(df_matrix,
main = "Heatmap of Extracellular Genes",
color = colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(10),
cluster_cols = FALSE,
show_rownames = F,
fontsize_col = 10,
cellwidth = 40,
)
This is what I get.
When I try using clustering, I got the error.
pheatmap(
mat = df_matrix,
scale = "row",
cluster_column = F,
show_rownames = TRUE,
drop_levels = TRUE,
fontsize = 5,
clustering_method = "complete",
main = "Hierachical Cluster Analysis"
)
Error in hclust(d, method = method) :
NA/NaN/Inf in foreign function call (arg 10)
Can someone help me with the code?
You can normalize the data using scale to archive a more uniform coloring. Here, the mean expression is set to 0 for each sample. Genes lower expressed than average have a negative z score:
library(tidyverse)
library(pheatmap)
data <- tribble(
~Gene, ~`HBEC-KT-01`, ~`HBEC-KT-02`, ~`HBEC-KT-03`, ~`HBEC-KT-04`, ~`HBEC-KT-05`, ~`Primarycells-03`, ~`Primarycells-04`, ~`Primarycells-05`,
"BPIFB1", 1.5726e+10, 1.5294e+10, 1.5294e+10, 1.4741e+10, 2.2427e+10, 2e+11, 1.04e+11, 1.51e+11,
"LCN2", 1.804e+10, 2.6444e+10, 2.8869e+10, 3.0337e+10, 1.0966e+10, 5.4007e+10, 5.6797e+10, 3.8414e+10,
"C3", 2.52e+11, 2.26e+11, 1.8e+11, 1.8e+11, 1.78e+11, 1.16e+11, 6.9398e+10, 7.8766e+10,
"MUC5AC", 15647000, 8353200, 12617000, 12221000, 29908000, 7.983e+10, 2.813e+10, 6.9147e+10,
"MUC5B", 965190000, 693910000, 779970000, 716110000, 1479700000, 9.0175e+10, 4.1764e+10, 5.0535e+10,
"ANXA2", 1.4705e+10, 1.8721e+10, 2.1592e+10, 1.8904e+10, 2.2657e+10, 2.4282e+10, 2.1708e+10, 1.6528e+10
)
data %>%
mutate(across(where(is.numeric), scale)) %>%
column_to_rownames("Gene") %>%
pheatmap(
scale = "row",
cluster_column = F,
show_rownames = FALSE,
show_colnames = TRUE,
treeheight_col = 0,
drop_levels = TRUE,
fontsize = 5,
clustering_method = "complete",
main = "Hierachical Cluster Analysis (z-score)",
)
Created on 2021-09-26 by the reprex package (v2.0.1)

How can I render a networkDynamic network using the MDSJ rendering engine in R?

I would like to render a dynamic network in R using the fast MDSJ library. Unfortunately, however, all the vertices' coordinates seem to be 0,0 using this rendering engine, which is not the case when using one of the other layouts (kamadakawai or Graphviz. If you paste the code below, you should be able to reproduce the problem.
if (!require("pacman")) install.packages("pacman")
library("pacman")
pacman::p_load(network, networkDynamic, ndtv)
#animation.mode = "MDSJ"
#animation.mode = "Graphviz"
animation.mode = "kamadakawai"
people <- c("A","B","C","D","E")
documents <- paste0("a",1:10)
edges <- data.frame(from = c("A","A","A","B","B","C","D"),
to = c("a1","a2","a3","a4","a5","a1","a1"),
active = c(1,2,3,3,4,4,4))
net <- network.initialize(0, directed = TRUE, bipartite = length(people))
add.vertices.networkDynamic(net, 5, vertex.pid = people)
add.vertices.networkDynamic(net, 10, vertex.pid = documents)
net %v% "vertex.names" <- c(people, documents)
net %v% "vertex.col" <- c(rep("blue", length(people)), rep("gray", length(documents)))
set.network.attribute(net,'vertex.pid','vertex.names')
add.edges.networkDynamic(net,
tail = get.vertex.id(net, edges[[1]]),
head = get.vertex.id(net, edges[[2]]),
edge.pid = paste0(edges[[1]], "->", edges[[2]]))
activate.edges(net, e = 1:7, at = edges[[3]])
reconcile.vertex.activity(net = net, mode = "encompass.edges", edge.active.default = FALSE)
slice.par <- list(start = 1, end = 4, interval = 1, aggregate.dur = 2, rule = "earliest")
compute.animation(net,
animation.mode = animation.mode,
slice.par = slice.par)
render.d3movie(net,
slice.par = slice.par,
displaylabels = TRUE,
output.mode = "htmlWidget",
vertex.col = 'vertex.col')
Using kamadakawai, one gets a dynamic view like this:
Using MDSJ, all slides look like this:
This code works on my system with MDSJ. Does it install correctly on yours? When it's first used, it has to download and install a Java application mdsj.jar.

Resources