sjt.grpmean results inside sjPlot are not correctly displayed - r

I have a problem with sjPlot command: sjt.grpmean
This is my example:
x <- rnorm(120,1230,220)
f <- c(rep("men",60),rep("women",60))
d <- data.frame(x,f)
library(sjPlot)
sjt.grpmean(var.cnt = d$x,
var.grp = d$f)
The result is just weird.
I try this:
x <- rnorm(120,1230,220)
f <- as.factor(c(rep("men",60),rep("women",60)))
d <- data.frame(x,f)
library(sjPlot)
sjt.grpmean(var.cnt = d$x,d$f)
With same weird result.
I Can use this workaround:
sjt.grpmean(var.cnt = d$x,
var.grp = d$f,
value.labels = c("men","women"))
But, why i need to use value.labels to fix?
is this a bug?
I will appreciate any help.
R version 3.3.2 (2016-10-31)
sjPlot 2.3.0

is this a bug?
Yes, it's a bug you found. I have already fixed it in the current dev-version on GitHub, a CRAN-update may follow in March...

Related

I get Error: invalid version specification ‘0,2’ when I use the function dm_draw() in r

I want to use the function dm_draw() to visualize a dm object but when I ran the command I get the error message " Error: invalid version specification ‘0,2’". I've tried the code included in the vignette "Visualizing dm objects" (https://cran.r-project.org/web/packages/dm/vignettes/tech-dm-draw.html) and I get the same error message when I run the dm_draw() function.
library(dm)
library(dplyr)
flights_dm_w_many_keys <- dm_nycflights13(color = FALSE)
dm_draw(flights_dm_w_many_keys)
I'm using dm version 0.2.7 and DiagrammeR 1.0.8. R version 4.1.2
I'm looking for a solution to visualize a dm object, it can be also different from dm_draw().
I hope someone can help me to get that done. Sorry for my broken English and thanks for your time, any type of help is appreciated.
You can use this code:
library(dm)
library(dplyr)
library(DiagrammeR)
library(DiagrammeRsvg)
# Use this function
dm_draw_svg = function(dm,...) {
if (!requireNamespace("DiagrammeRsvg", quietly = TRUE)) {
stop(
"Package \"DiagrammeRsvg\" must be installed to use this function.",
call. = FALSE
)
}
dm::dm_draw(dm = dm, ...) %>%
DiagrammeRsvg::export_svg() %>%
htmltools::HTML() %>%
htmltools::html_print()
}
flights_dm_w_many_keys <- dm_nycflights13(color = FALSE)
# plot
dm_draw_svg(flights_dm_w_many_keys)
Output:

Caret featurePlot giving "object cannot be coerced" error

Code that use to run:
library(caret)
library(tidyverse)
data_set <- diamonds %>%
filter(row_number() <= 1000) %>%
select(carat, depth)
featurePlot(x = data_set[,-1], y = data_set[,1])
now fails with
Error in diff(as.numeric(y[ord])) :
(list) object cannot be coerced to type 'double'
Below also fails:
featurePlot(x = as.data.frame(data_set[,-1]), y = as.data.frame(data_set[,1]))
But below works:
featurePlot(x = data_set$depth, y = data_set$carat)
Seeking a way to use sub setting by column number.
I think there is something going on with the tibble class---I've encountered something similar. Try the following. It works for me:
class(data_set) <- "data.frame"
featurePlot(x = data_set[,-1], y = data_set[,1])
You might want to file an issue on GitHub, because it is indeed strange that your second approach (which is very sensible) does not work. I can confirm that both approaches that you tried also generate the same errors for me.

Heatmap Plot -- Getting Error

I am looking at this link.
https://bioconductor.org/packages/devel/bioc/vignettes/ComplexHeatmap/inst/doc/s2.single_heatmap.html
This first several lines of code work fine, but now I'm getting this error.
Error in Heatmap(mat) : could not find function "Heatmap"
I'm no too familiar with R. Can someone tell me what is wrong here? Thanks.
Try running the following code:
source("https://bioconductor.org/biocLite.R")
if(!require(ComplexHeatmap)) biocLite("ComplexHeatmap")
if(!require(circlize)) install.packages('circlize')
# -------------------------------------------------------
library(ComplexHeatmap)
library(circlize)
set.seed(123)
mat = cbind(rbind(matrix(rnorm(16, -1), 4), matrix(rnorm(32, 1), 8)),
rbind(matrix(rnorm(24, 1), 4), matrix(rnorm(48, -1), 8)))
# permute the rows and columns
mat = mat[sample(nrow(mat), nrow(mat)), sample(ncol(mat), ncol(mat))]
rownames(mat) = paste0("R", 1:12)
colnames(mat) = paste0("C", 1:10)
Heatmap(mat)
Does this work for you?
If yes, your problem was that you had not installed the necessary packages before loading them with library. The first 3 lines of the code I provided is simply checking if you have installed the necessary packages, and then if not, it installs them.

pheatmap - cytokine_annotation

I tried to develope cytokine_annotation in pheatmap and get error message
Error in seq.int(rx[1L], rx[2L], length.out = nb) : 'from' must be
finite
R version 3.3.3
pheatmap_1.0.8
Reproducible example:
#Using cytokine annotations
M<-matrix(rnorm(8*20),ncol=8)
row_annotation<-data.frame(A=gl(4,nrow(M)/4),B=gl(4,nrow(M)/4))
eg<-expand.grid(factor(c(0,1)),factor(c(0,1)),factor(c(0,1)))
colnames(eg)<-c("IFNg","TNFa","IL2")
rownames(eg)<-apply(eg,1,function(x)paste0(x,collapse=""))
rownames(M)<-1:nrow(M)
colnames(M)<-rownames(eg)
cytokine_annotation=eg
pheatmap(M,annotation=annotation,row_annotation=row_annotation,annotation_legend=TRUE,row_annotation_legend=TRUE,cluster_rows=FALSE,cytokine_annotation=cytokine_annotation,cluster_cols=FALSE)
On my R 3.3.3 with pheatmap_1.0.8 the following code works:
set.seed(1)
M <- matrix(rnorm(8*20),ncol=8)
row_annotation <- data.frame(A=gl(4,nrow(M)/4),B=gl(4,nrow(M)/4))
eg <- expand.grid(factor(c(0,1)),factor(c(0,1)),factor(c(0,1)))
colnames(eg) <- c("IFNg","TNFa","IL2")
rownames(eg) <- apply(eg,1,function(x)paste0(x,collapse=""))
rownames(M) <- 1:nrow(M)
colnames(M) <- rownames(eg)
cytokine_annotation <- eg
library(pheatmap)
pheatmap(M, annotation=cytokine_annotation, row_annotation=row_annotation,
annotation_legend=TRUE, row_annotation_legend=TRUE, cluster_rows=FALSE,
cytokine_annotation=cytokine_annotation, cluster_cols=FALSE)
I also had this problem and found that simply restarting R solved this issue.

Why does `options(digits=3)` get ignored in `knitr'?

When I run the following line by line in R it works fine, but with knitr the options(digits=3) gets ignored.
Why? Any solutions?
<<cor>>=
#mock up data set.
x <- c(rnorm(100))
y <- c(rnorm(100))
z <- c(rnorm(100))
df <- as.data.frame(cbind(x,y,z))
df$x<- as.numeric(df$x)
df$y<- as.numeric(df$y)
df$z<- as.numeric(df$z)
options(digits=3)
cor(df, use = 'na.or.complete', method = c("spearman"))
#
I found a solution while searching for a different issue. Leave out options(digits=3) and use
round(cor(df, use = "na.or.complete", method = c("spearman")), digits = 3)
Which leaves the question why the options(...) doesn't work. But I can happily live with that!
Thanks everyone for their time!
Gerit

Resources