I am conducting "convergent cross mapping" analysis for a multivariate data series. Unfortunately, I am struggeling with the function "ccm_means" of the R-package "rEDM". It is "deprecated" and I did not find a proper alternative so far. Do you know any alternative package or function for conducting CCM = convergent cross mapping analysis?
Explicitely, I am talking about this piece of code:
library(rEDM)
data(sardine_anchovy_sst)
anchovy_xmap_sst <- ccm(sardine_anchovy_sst, E = 3, lib_column = "anchovy",
target_column = "np_sst", lib_sizes = seq(10, 80, by = 10), num_samples = 100,
random_libs = TRUE, replace = TRUE, silent = TRUE)
sst_xmap_anchovy <- ccm(sardine_anchovy_sst, E = 3, lib_column = "np_sst", target_column = "anchovy",
lib_sizes = seq(10, 80, by = 10), num_samples = 100, random_libs = TRUE,
replace = TRUE, silent = TRUE)
str(anchovy_xmap_sst)
a_xmap_t_means <- ccm_means(anchovy_xmap_sst)
t_xmap_a_means <- ccm_means(sst_xmap_anchovy)
#####--------> ERROR POPS UP HERE
plot(a_xmap_t_means$lib_size, pmax(0, a_xmap_t_means$rho), type = "l", col = "red",
xlab = "Library Size", ylab = "Cross Map Skill (rho)", ylim = c(0, 1))
lines(t_xmap_a_means$lib_size, pmax(0, t_xmap_a_means$rho), col = "blue")
legend(x = "topleft", legend = c("anchovy xmap SST", "SST xmap anchovy"), col = c("red",
"blue"), lwd = 1, bty = "n", inset = 0.02, cex = 0.8)*
Thank you very much for ur help.
KR,
Chris
Related
I'm using VennDiagram to illustrate the overlap between distinct sets of customers -- in total and for a particular sub-segment. The problem that I'm having is that it appears VennDiagram automatically orders the circles in the output from largest to smallest. In the two diagrams I'm creating the relative size of the two populations is flipping, so in the output the populations/colors of the diagram are reversed. I want to put these side by side in a document, and the flipping of population order makes side by side comparison a little confusing.
Sample code for each is below -- is there a way to manually force the ordering of sets in the output, so that populations are ordered in the same sequence?
Thank you -
venn.plot <- venn.diagram(
x = list(
"AD" = 1:703814,
"WM" = 672279:1086933
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Total.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Total Populations",
main.cex = 2,
sub.cex = 1.5
);
venn.plot <- venn.diagram(
x = list(
"AD" = 1:183727,
"WM" = 173073:383052
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Target.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Target Populations",
main.cex = 2,
sub.cex = 1.5
);
use an if statement to see if the second set is larger than the first. if yes, then add 180 degrees to rotation.
It can be solved by altering the gList object from draw.pairwise.venn() function. venn.diagram() is a wrapper for many draw.____.venn() functions (Eg: pairwise, quad, quintuple, single etc.,)
Use an if statement to find any switch in the labels of population in your example. If true, then change inverted = TRUE and switch labels.
Also use ind = FALSE to prevent drawing the diagram.
I used your example to show solution for one of two venn diagrams you posted in your question.
packageVersion("VennDiagram")
# [1] ‘1.6.17’
AD <- 1:703814
WM <- 672279:1086933
overlap <- calculate.overlap(x = list('AD' = AD, 'WM' = WM))
area_overlap <- sapply(overlap, length)
g <- draw.pairwise.venn(area1 = area_overlap[1],
area2 = area_overlap[2],
cross.area = area_overlap[3],
category = c("AD", "WM"),
ind = FALSE,
inverted = FALSE,
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 6,
cat.cex = 6,
cat.col = c("black", "black"),
cat.dist = c(-0.16, -0.09),
cat.pos = c(0,10),
rotation.degree = 35)
# check for switch in labels
if(area_overlap[1] != (as.integer(g[[5]]$label) + as.integer(g[[7]]$label)) && area_overlap[2] != (as.integer(g[[6]]$label) + as.integer(g[[7]]$label))){
# change inverted to TRUE
g <- draw.pairwise.venn(area1 = area_overlap[1],
area2 = area_overlap[2],
cross.area = area_overlap[3],
category = c("AD", "WM"),
ind = FALSE,
inverted = TRUE,
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 6,
cat.cex = 6,
cat.col = c("black", "black"),
cat.dist = c(-0.16, -0.09),
cat.pos = c(0,10),
rotation.degree = 35)
# switch labels
tmp_var <- g[[6]]$label
g[[6]]$label <- g[[5]]$label
g[[5]]$label <- tmp_var
rm(tmp_var)
}
jpeg("AD_vs_WM_Total_new.jpg", width = 1200, height = 1200)
plot.new()
title(main = "AD vs. WM", sub = "Total Populations", cex.main = 6, cex.sub = 5, line = -4, outer = TRUE)
grid.draw(g)
dev.off()
If statement would do the trick but it seems a bit heavy handed for such a small task. I think you could simply add the following line into your script
inverted=length(x$AD) < length(x$WM)
And that should do the trick (when WM is longer than AD statement is True and plot is inverted).
This didn't work for me. The data in the circles flipped, but the labels on the circles stayed in place. The rotation approach worked, though.
I use the example from the site, but I want to remove the points so that only the connection of the medians remains.
My code.
# for reproducibility
set.seed(123)
library(ggstatsplot)
df_disgust <- dplyr::filter(bugs_long, condition %in% c("LDHF", "HDHF"))
p2 <-
ggstatsplot::ggwithinstats(
data = df_disgust,
x = condition,
y = desire,
xlab = "Condition",
ylab = "Desire to kill bugs",
type = "np",
conf.level = 0.99,
title = "Non-parametric Test",
package = "ggsci",
palette = "uniform_startrek",
point.args = list(size = 0, alpha = 0.5),
point.path = FALSE,
centrality.plotting = TRUE,
outlier.tagging = T,
ggtheme = ggthemes::theme_map()
)
ggstatsplot::combine_plots(
plotlist = list(p2),
plotgrid.args = list(nrow = 2),
annotation.args = list(
title = "Effect of disgust on desire to kill bugs ",
caption = "Source: Bugs dataset from `jmv` R package"
)
)
The parameter that is responsible for the points, as I understood point.args = list(size = 3, alpha = 0.5),but when I set size = 0 the dots don't disappear.
I didn't find any other parameters that would be responsible for the points
You can just set the transparency for respective geometric layers to 0.
library(ggstatsplot)
df_disgust <- dplyr::filter(bugs_long, condition %in% c("LDHF", "HDHF"))
ggwithinstats(df_disgust,
condition,
desire,
point.args = list(alpha = 0),
centrality.point.args = list(alpha = 0),
point.path = FALSE
)
grouped_ggwithinstats(df_disgust,
condition,
desire,
grouping.var = gender,
point.args = list(alpha = 0),
centrality.point.args = list(alpha = 0),
point.path = FALSE
)
Created on 2022-05-13 by the reprex package (v2.0.1.9000)
I am creating forest plots using the meta package in R. I have added a line of text using text.addline1 (see bottom of plot). How do I make that text bold? It says see "gpar" in the cran documentation but I can't work it out.
library(meta)
## make data
df1 <- data.frame(matrix(, nrow=14, ncol=6))
colnames(df1) <- c("estimate", "std.error", "N", "study", "Exposure", "or" )
df1$estimate <- c("1.0588634", "1.0210044", "1.0484577", "0.9872621", "1.0122652",
"0.9934573", "0.9429622", "1.0320382", "0.9654555", "1.0499671", "1.0400071",
"1.0208341", "0.9954885", "0.9879208")
df1$std.error <- c(0.054092871, 0.037674050, 0.093067276, 0.054198110, 0.008714173, 0.010266589,
0.056993648, 0.058017078, 0.058050610, 0.089878607, 0.056951120, 0.011041428,
0.013533755, 0.090526260)
df1$N <- 500
df1$study <- "Study"
df1$Exposure <- "Smoker"
df1$Exposure[7:14] <- "Non smoker"
df1$or <- c(0.057196058, 0.020786829, 0.047320225, -0.012819723, 0.012190549, -0.006564245,
-0.058729114, 0.031535708, -0.035155279, 0.048758876, 0.039227559, 0.020620087,
-0.004521733, -0.012152786)
meta_obj <- metagen(or, std.error, sm = "OR", data = df1,
studlab = study, comb.fixed = TRUE, comb.random = FALSE, byvar = Exposure)
# FOREST ------------------------------------------------------------------
forest(meta_obj, smlab = "Text here", spacing = 1.5,
xlab = "Odds ratio",
xlim = c(0.5, 2),
leftcols = c("studlab", "N"),
col.diamond = "red", col.by = "black",
overall.hetstat = FALSE,
print.I2 = TRUE, print.tau2 = FALSE,
subgroup = T, overall = F,
text.addline1 = "HOW DO I MAKE THIS BOLD?",
ref = 1)
See argument 'ff.addline':
forest(meta_obj, smlab = "Text here", spacing = 1.5,
xlab = "Odds ratio",
xlim = c(0.5, 2),
leftcols = c("studlab", "N"),
col.diamond = "red", col.by = "black",
overall.hetstat = FALSE,
print.I2 = TRUE, print.tau2 = FALSE,
subgroup = T, overall = F,
ref = 1,
text.addline1 = "USE ARGUMENT 'ff.addline = \"bold\"'",
ff.addline = "bold",
fs.addline = 12,
colgap.left = "2.8cm")
I like the package EnhancedVolcano. My data is RNAseq and I analyse it with DESeq2. I want to plot the results as a volcanoplot where I highlight a list of genes of my choice picked_genes. I have succeded in changing pointSize and I am using SelectLab to highlight but when I want to give the chosen genes another color I get stuck. I have added a logical vector to my results file specifying which genes to highlight. I have tried
col = ifelse...
It doesn't work, all dots are grey.
EnhancedVolcano(res_complete,
lab = res_complete$gene_name,
x = "log2FoldChange",
y = "pvalue",
pCutoff = 10e-3,
FCcutoff = 1,
xlim = c(-10, 10),
ylim = c(0, -log10(10e-12)),
col = (ifelse(res_complete$picked_genes == T, "forestgreen", "grey60")),
pointSize = (ifelse(res_complete$picked_genes == T, 5, 0.5)),
labSize = 2.5,
selectLab = picked_genes,
shape = 16,
shade = res_complete$picked_genes == T,
shadeFill = "forestgreen",
shadeSize = 5,
shadeLabel = res_complete$picked_genes,
boxedLabels = TRUE,
title = "DESeq2 results",
subtitle = "Differential expression HC vs RA",
caption = "FC cutoff, 1; p-value cutoff, 10e-3",
legendPosition = "right",
legendLabSize = 14,
colAlpha = 0.9,
drawConnectors = TRUE,
hline = c(10e-8),
widthConnectors = 0.2)
I have also tried:
colCustom =ifelse...
But I get an error message...
Error: Aesthetics must be either length 1 or the same as the data (58735): colour
EnhancedVolcano(res_complete,
lab = res_complete$gene_name,
x = "log2FoldChange",
y = "pvalue",
pCutoff = 10e-3,
FCcutoff = 1,
xlim = c(-10, 10),
ylim = c(0, -log10(10e-12)),
colCustom = (ifelse(res_complete$picked_genes == T, "forestgreen", "grey60")),
pointSize = (ifelse(res_complete$picked_genes == T, 5, 0.5)),
labSize = 2.5,
selectLab = picked_genes,
shape = 16,
shade = res_complete$picked_genes == T,
shadeFill = "forestgreen",
shadeSize = 5,
shadeLabel = res_complete$picked_genes,
boxedLabels = TRUE,
title = "DESeq2 results",
subtitle = "Differential expression HC vs RA",
caption = "FC cutoff, 1; p-value cutoff, 10e-3",
legendPosition = "right",
legendLabSize = 14,
colAlpha = 0.9,
drawConnectors = TRUE,
hline = c(10e-8),
widthConnectors = 0.2)
Can someone come up with a solution to this problem?
I found it, finally I understood it. colCustom needs a pair for each point, a color and a name. I created the matrix keyvals
keyvals <- ifelse(
res_complet$picked_genes < T, 'grey60',
'forestgreen')
names(keyvals)[keyvals == 'forestgreen'] <- 'picked'
names(keyvals)[keyvals == 'grey60'] <- 'rest'
`
Than I used it to replace the col=
`
EnhancedVolcano(res_complete,
lab = res_complete$gene_name,
x = "log2FoldChange",
y = "pvalue",
pCutoff = 10e-3,
FCcutoff = 1,
xlim = c(-10, 10),
ylim = c(0, -log10(10e-12)),
pointSize = (ifelse(res_complete$picked_genes == T, 5, 0.5)),
labSize = 2.5,
shape = c(19, 19, 19, 19),
selectLab = picked_genes,
boxedLabels = TRUE,
title = "DESeq2 results",
subtitle = "Differential expression HC vs RA",
caption = "FC cutoff, 1; p-value cutoff, 10e-3",
legendPosition = "right",
legendLabSize = 14,
colCustom = keyvals,
colAlpha = 0.9,
drawConnectors = TRUE,
hline = c(10e-8),
widthConnectors = 0.2)
`
In order to get all points visible I sorted my results dataframe after the logical column res_complete$picked_genes and made the volcano again. Voilá
How do I change the size of the trace label, need to make it bigger. Is there any cex. function that I can use ?
This is my code
x <- interaction.plot(x.factor = data_flokvel$Vél.nr.,
trace.factor = data_flokvel$d ,
response = data_flokvel$Gallar..,
fun = mean, type = "b", fixed = TRUE,legend = TRUE,
col= c(1:6),lwd = 3, cex.lab= 1.5, cex.axis = 1.5,
cex.main = 1.5,lty = 1, ylab = "Flökunargallahlutfall (%)",
xlab = "Vél númer", trace.label = "Þyngd karfa í kg")
I am using Rstudio 0.99
and a reproducible example:
with(ToothGrowth, interaction.plot(dose, supp, len, fixed = TRUE) ))