error in sjPlot sjp.xtab command used to get "cleanest" graphic? - r

I am trying to generate a bar plot with this data:
library(sjPlot)
library(sjstats)
data("efc")
i use the following to generate the default xtab plot from the sjPlot.
sjp.xtab(x = efc$e42dep,
grp = efc$c82cop1)
But i prefer show only a "cleanest" plot, without information (i prefer to link to a table if you want the specific data), so i try this:
sjp.xtab(x = efc$e42dep,
grp = efc$c82cop1,show.total = F, show.n = F,show.prc = F)
but i get this
Error in sjp.xtab(x = efc$e42dep, grp = efc$c82cop1, show.total = F,
show.n = F, : objeto 'ggvaluelabels' no encontrado
i use R in a Spanish language OS, so...
is basically
object 'ggvaluelabels' not found
What am i doing wrong?

use show.values = FALSE to prevent annotating the graph.
sjp.xtab(x = efc$e42dep, grp = efc$c82cop1)
# show.values = FALSE
sjp.xtab(x = efc$e42dep, grp = efc$c82cop1, show.values = FALSE )
sjp.xtab(x = efc$e42dep, grp = efc$c82cop1,show.total = F, show.n = F,show.prc = F, show.values = FALSE)

Related

Add a title to gprofiler2 gosttable in R

Hello I'm a new bioinformatician so bear with me please!
I'm using the gprofiler2 to run GO/KEGG analysis in R using emacs/ess and I want to add a title to the table it offers:
publish_gosttable(gostres, highlight_terms = gostres$result[c(1:2,10,120),],
use_colors = TRUE,
show_columns = c("source", "term_name", "term_size", "intersection_size"),
filename = NULL)
I have tried the title(), tab_header() function but I can't seem to be able to add a title. My question is if there is some other function or package that would allow me to add it instead of having to do it manually.
The code so far
GOresult <- gost(
geneid1up$gene,
organism = "hsapiens",
ordered_query = FALSE,
multi_query = FALSE,
significant = TRUE,
exclude_iea = FALSE,
measure_underrepresentation = FALSE,
evcodes = FALSE,
user_threshold = 0.05,
correction_method = "gSCS",
domain_scope = "annotated",
custom_bg = NULL,
numeric_ns = "",
sources = c("GO:BP","GO:MF","GO:CC","KEGG"),
as_short_link = FALSE)
GOresult1 <- as.data.frame(GOresult$result)
GOresult1$minuslog10pval <- -log10(GOresult1$p_value)
names(GOresult1)[15] <- "-log10(pval)"
GOresult2 <- GOresult1[order(GOresult1$p_value, decreasing=F),]
plot1 <- publish_gosttable(GOresult2, highlight_terms = GOresult2[c(1:20),],
use_colors = FALSE,
show_columns = c("source", "term_name", "term_size", "intersection_size","-log10(pval)"),
filename = NULL)
Does this do the job?
library(gprofiler2)
library(ggplot2)
gostres <- gost(query = c("X:1000:1000000", "rs17396340", "GO:0005005", "ENSG00000156103", "NLRP1"),
organism = "hsapiens", ordered_query = FALSE,
multi_query = FALSE, significant = TRUE, exclude_iea = FALSE,
measure_underrepresentation = FALSE, evcodes = FALSE,
user_threshold = 0.05, correction_method = "g_SCS",
domain_scope = "annotated", custom_bg = NULL,
numeric_ns = "", sources = NULL, as_short_link = FALSE)
publish_gosttable(gostres, highlight_terms = gostres$result[c(1:2,10,120),],
use_colors = TRUE,
show_columns = c("source", "term_name", "term_size", "intersection_size"),
filename = NULL)+
ggtitle('Your Title')
Result:
The trick is that the plot is a ggplot objet. Therefore you can add the title using +ggtitle('Your Title') after your plot code (as in my example)

uwot is throwing an error running the Monocle3 R package's "find_gene_module()" function, likely as an issue with how my data is formatted

I am trying to run the Monocle3 function find_gene_modules() on a cell_data_set (cds) but am getting a variety of errors in this. I have not had any other issues before this. I am working with an imported Seurat object. My first error came back stating that the number of rows were not the same between my cds and cds#preprocess_aux$gene_loadings values. I took a look and it seems my gene loadings were a list under cds#preprocess_aux#listData$gene_loadings. I then ran the following code to make a dataframe version of the gene loadings:
test <- seurat#assays$RNA#counts#Dimnames[[1]]
test <- as.data.frame(test)
cds#preprocess_aux$gene_loadings <- test
rownames(cds#preprocess_aux$gene_loadings) <- cds#preprocess_aux$gene_loadings[,1]
Which created a cds#preprocess_aux$gene_loadings dataframe with the same number of rows and row names as my cds. This resolved my original error but now led to a new error being thrown from uwot as:
15:34:02 UMAP embedding parameters a = 1.577 b = 0.8951
Error in uwot(X = X, n_neighbors = n_neighbors, n_components = n_components, :
No numeric columns found
Running traceback() produces the following information.
> traceback()
4: stop("No numeric columns found")
3: uwot(X = X, n_neighbors = n_neighbors, n_components = n_components,
metric = metric, n_epochs = n_epochs, alpha = learning_rate,
scale = scale, init = init, init_sdev = init_sdev, spread = spread,
min_dist = min_dist, set_op_mix_ratio = set_op_mix_ratio,
local_connectivity = local_connectivity, bandwidth = bandwidth,
gamma = repulsion_strength, negative_sample_rate = negative_sample_rate,
a = a, b = b, nn_method = nn_method, n_trees = n_trees, search_k = search_k,
method = "umap", approx_pow = approx_pow, n_threads = n_threads,
n_sgd_threads = n_sgd_threads, grain_size = grain_size, y = y,
target_n_neighbors = target_n_neighbors, target_weight = target_weight,
target_metric = target_metric, pca = pca, pca_center = pca_center,
pca_method = pca_method, pcg_rand = pcg_rand, fast_sgd = fast_sgd,
ret_model = ret_model || "model" %in% ret_extra, ret_nn = ret_nn ||
"nn" %in% ret_extra, ret_fgraph = "fgraph" %in% ret_extra,
batch = batch, opt_args = opt_args, epoch_callback = epoch_callback,
tmpdir = tempdir(), verbose = verbose)
2: uwot::umap(as.matrix(preprocess_mat), n_components = max_components,
metric = umap.metric, min_dist = umap.min_dist, n_neighbors = umap.n_neighbors,
fast_sgd = umap.fast_sgd, n_threads = cores, verbose = verbose,
nn_method = umap.nn_method, ...)
1: find_gene_modules(cds[pr_deg_ids, ], reduction_method = "UMAP",
max_components = 2, umap.metric = "cosine", umap.min_dist = 0.1,
umap.n_neighbors = 15L, umap.fast_sgd = FALSE, umap.nn_method = "annoy",
k = 20, leiden_iter = 1, partition_qval = 0.05, weight = FALSE,
resolution = 0.001, random_seed = 0L, cores = 1, verbose = T)
I really have no idea what I am doing wrong or how to proceed from here. Does anyone with experience with uwot know where my error is coming from? Really appreciate the help!

Create a script with 2 vectors in R

I'm using Heatmap from the package complexheatmap
in the script, I need to create a variable ha_column that I will incorporate into my script.
ha_column = HeatmapAnnotation (df = data.frame(type1=c(rep("name1",5), rep("name2",5),rep("name3",5), col = list(type1=c("name1" = "#DCDCDC", "name2" = "#DC928B", "name2"="#BA72D3")))))
I have 2 vectors:
vectors1=c("name1","name2","name3)
vectors2=c("#DCDCDC","#DC928B","#BA72D3")
and the idea is to reproduce the above script with these two vectors.
I tried:
paste0("ha_column = HeatmapAnnotation(df = data.frame(type1 = c(rep(",vectors1,", 5),col = list(type1 = c(",vectors1,"=",vectors2,")))")
bu it only paste line by line such as:
[1] "ha_column = HeatmapAnnotation(df = data.frame(type1 = c(rep(name1, 5),col = list(type1 = c(name1=#DCDCDC)))"
[2] "ha_column = HeatmapAnnotation(df = data.frame(type1 = c(rep(name2, 5),col = list(type1 = c(name2=#DC928B)))"
[3] "ha_column = HeatmapAnnotation(df = data.frame(type1 = c(rep(name3, 5),col = list(type1 = c(name3=#BA72D3)))"
instead of doing what I want ...
Does anyone have an idea?
Thanks for your time.
It's generally not a good idea to build code as a string. Instead think of building a function to do what you want.
You could do something line
ha_column_fun = function(names, colors) {
HeatmapAnnotation(
df = data.frame(type1 = rep(names, each=5)),
col = list(type1=setNames(colors, names))
)
}
And then you could call it with
ha_column = ha_column_fun(vectors1, vectors2)

Error in `V<-`(`*tmp*`, value = `*vtmp*`) : invalid indexing

I used the bibliometrix function in R, and want to plot some useful graphs.
library(bibliometrix)
??bibliometrix
D<-readFiles("E:\\RE\\savedrecs.txt")
M <- convert2df(D,dbsource = "isi", format= "plaintext")
results <- biblioAnalysis(M ,sep = ";" )
S<- summary(object=results,k=10, pause=FALSE)
plot(x=results,k=10,pause=FALSE)
options(width=100)
S <- summary(object = results, k = 10, pause = FALSE)
NetMatrix <- biblioNetwork(M1, analysis = "co-occurrences", network = "author_keywords", sep = ";")
S <- normalizeSimilarity(NetMatrix, type = "association")
net <- networkPlot(S, n = 200, Title = "co-occurrence network",type="fruchterman", labelsize = 0.7, halo = FALSE, cluster = "walktrap",remove.isolates=FALSE, remove.multiple=FALSE, noloops=TRUE, weighted=TRUE)
res <- thematicMap(net, NetMatrix, S)
plot(res$map)
But in the net <- networkPlot(S, n = 200, Title = "co-occurrence network",type="fruchterman", labelsize = 0.7, halo = FALSE, cluster = "walktrap",remove.isolates=FALSE, remove.multiple=FALSE, noloops=TRUE, weighted=TRUE), it shows error
Error in V<-(*tmp*, value = *vtmp*) : invalid indexing
. Also I cannot do the CR, it always shows unlistCR. I cannot use the NetMatrix function neither.
Some help me plsssssssss
The problem is in the data itself not in the code you presented. When I downloaded the data from bibliometrix.com and changed M1 to M (typo?) in biblioNetwork function call everything worked perfectly. Please see the code below:
library(bibliometrix)
# Plot bibliometric analysis results
D <- readFiles("http://www.bibliometrix.org/datasets/savedrecs.txt")
M <- convert2df(D, dbsource = "isi", format= "plaintext")
results <- biblioAnalysis(M, sep = ";")
S <- summary(results)
plot(x = results, k = 10, pause = FALSE)
# Plot Bibliographic Network
options(width = 100)
S <- summary(object = results, k = 10, pause = FALSE)
NetMatrix <- biblioNetwork(M, analysis = "co-occurrences", network = "author_keywords", sep = ";")
S <- normalizeSimilarity(NetMatrix, type = "association")
net <- networkPlot(S, n = 200, Title = "co-occurrence network", type = "fruchterman",
labelsize = 0.7, halo = FALSE, cluster = "walktrap",
remove.isolates = FALSE, remove.multiple = FALSE, noloops = TRUE, weighted = TRUE)
# Plot Thematic Map
res <- thematicMap(net, NetMatrix, S)
str(M)
plot(res$map)

'use.edge.length = FALSE' doesn't seem to work when using plotBranchbyTrait() in phytools

I'm trying to create a phylogeny where the branch lengths that I've coded are represented by colour rather than length. So I want the branch lengths to be equal.
Here is my code:
plotBranchbyTrait(tree.scaled, tree.scaled$edge.length, mode=c("edges"),palette="rainbow", use.edge.length = FALSE, node.depth = 2)
It's my understanding that use.edge.length = FALSE should make the branch lengths equal, and it does this if I code the tree using plot.phylo(). But the tree still shows up with the branch lengths when I use plotBranchbyTrait(). Anyone know how to get around this?
Unfortunately, optional arguments (...) are not directly passed to plot.phylo in the plotBranchbyTrait function. One non-elegant way to fix that is to modify the body directly in R to add a hard coded use.edge.length = FALSE option.
You can do this by creating a new function and modify it using body(foo)[[line_of_interest]] <- substitute(my_new_line <- that_does_something). The following example should work:
## Back up the function
plotBranchbyTrait_no_edge_length <- phytools::plotBranchbyTrait
## The line to modify:
body(plotBranchbyTrait_no_edge_length)[[34]]
# xx <- plot.phylo(tree, type = type, show.tip.label = show.tip.label,
# show.node.label = show.node.label, edge.color = colors, edge.width = edge.width,
# edge.lty = edge.lty, font = font, cex = cex, adj = adj, srt = srt,
# no.margin = no.margin, root.edge = root.edge, label.offset = label.offset,
# underscore = underscore, x.lim = x.lim, y.lim = y.lim, direction = direction,
# lab4ut = lab4ut, tip.color = tip.color, plot = plot, rotate.tree = rotate.tree,
# open.angle = open.angle, lend = 2, new = FALSE)
## Modify the line 34 by adding `use.edge.length = FALSE`
body(plotBranchbyTrait_no_edge_length)[[34]] <- substitute( xx <- plot.phylo(use.edge.length = FALSE, tree, type = type, show.tip.label = show.tip.label, show.node.label = show.node.label, edge.color = colors, edge.width = edge.width, edge.lty = edge.lty, font = font, cex = cex, adj = adj, srt = srt, no.margin = no.margin, root.edge = root.edge, label.offset = label.offset, underscore = underscore, x.lim = x.lim, y.lim = y.lim, direction = direction, lab4ut = lab4ut, tip.color = tip.color, plot = plot, rotate.tree = rotate.tree, open.angle = open.angle, lend = 2, new = FALSE) )
## Testing whether it worked
library(phytools)
tree <- pbtree(n=50)
x <- fastBM(tree)
## With use.edge.length = TRUE (default)
plotBranchbyTrait(tree, x, mode = "tips", edge.width = 4, prompt = FALSE)
## With use.edge.length = FALSE
plotBranchbyTrait_no_edge_length(tree, x, mode = "tips", edge.width = 4, prompt = FALSE)
You can find more on how to modify functions here.

Resources