gforge / gmisc Goto Github PK
View Code? Open in Web Editor NEWAn R package for creating tables, some plots and other useful utilities too small to merit their own package
An R package for creating tables, some plots and other useful utilities too small to merit their own package
When x
is a character this unhelpful error occurs
getDescriptionStatsBy(
as.character(mtcars$am), mtcars$gear,
show_all_values = TRUE
)
Error in `substr<-`(`*tmp*`, 1, 1, value = character(0)) :
replacing substrings in a non-character object
In addition: Warning message:
In if (unique(sapply(t, length)) == 1) name <- sprintf("%s %s", :
the condition has length > 1 and only the first element will be used
Note the substr<-
error goes away if show_all_values = FALSE
. These are easily fixed by factor(x)
getDescriptionStatsBy(
factor(as.character(mtcars$am)), mtcars$gear,
show_all_values = TRUE
)
The difference is when we get to t
t <- structure(list(`3` = structure(c("15 (100.0%)", "0 (0.0%)"), .Dim = c(2L,
1L), .Dimnames = list(c("0", "1"), NULL)), `4` = structure(c("4 (33.3%)",
"8 (66.7%)"), .Dim = c(2L, 1L), .Dimnames = list(c("0", "1"),
NULL)), `5` = structure(c("0 (0.0%)", "5 (100.0%)"), .Dim = c(2L,
1L), .Dimnames = list(c("0", "1"), NULL))), .Dim = 3L, .Dimnames = structure(list(
by = c("3", "4", "5")), .Names = "by"), call = by.default(data = x,
INDICES = by, FUN = prop_fn, html = html, digits = digits,
number_first = numbers_first, useNA = useNA, useNA.digits = useNA.digits,
default_ref = default_ref, percentage_sign = percentage_sign), class = "by")
# by: 3
# [,1]
# 0 "15 (100.0%)"
# 1 "0 (0.0%)"
# -----------------------------------------------------------------------------
# by: 4
# [,1]
# 0 "4 (33.3%)"
# 1 "8 (66.7%)"
# -----------------------------------------------------------------------------
# by: 5
# [,1]
# 0 "0 (0.0%)"
# 1 "5 (100.0%)"
and this line if (unique(sapply(t, length)) == 1)
will be FALSE
since all of t
are length 2.
If t
was a character we would get
# by: 3
# [,1]
# 0 "15 (100.0%)"
# -----------------------------------------------------------------------------
# by: 4
# [,1]
# 0 "4 (33.3%)"
# 1 "8 (66.7%)"
# -----------------------------------------------------------------------------
# by: 5
# [,1]
# 1 "5 (100.0%)"
and if (unique(sapply(t, length)) == 1)
would throw that error and the first value would be TRUE
or FALSE
depending on the data, so the evaluation of the next line is a crapshoot.
Also the next line assumes that x
is a factor anyway:
name <- sprintf("%s %s", capitalize(levels(x)[default_ref]),
tolower(name))
The easiest fix would be for the user to make sure x
is a factor before running, but sometimes I forget and new users might not know nor can I find this suggestion explicitly in the docs, and the error doesn't make things immediately clear.
Possible solutions:
explicitly state x
needs to be numeric or a factor
coerce character to factor quietly or with a message/warning
if (all(unique(sapply(t, length)) == 1))
might also achieve the same result since the note suggests this line should only be evaluated if we are dealing with one row
As discussed in here #56, one might want to change the text size if there are too many boxes. Height and wright of the box change according to the defined cex
, but the padding remained the same. The padding will be large if the text size is small. This was caused by the code here.
Multiply the padding value by cex
, let the padding change over cex
.
The height calculation for boxPropGrob
is wrong when there are several lines of text. I've attempted to fix it, but I haven't succeeded in working out the problem so far. Multiline labels work fine for normal boxGrob
s, so it might be something to do with the additional height of the "main" label. However, boxPropGrob
also uses the prConvTxt2Height
helper to calculate text height by counting lines and multiplying by the lines
unit, whereas the normal boxProp
just measures the height of the text grob directly.
Some other issues with boxPropGrob
:
missing(label)
but it's not possible to call the function without label
, and other parts of the function assume label
is present.txt_gp
, txt_left_gp
, txt_right_gp
options are all ignored.library(Gmisc)
#> Loading required package: Rcpp
#> Loading required package: htmlTable
library(grid)
grid.newpage()
boxPropGrob("Label", "Left1\nLeft2\nLeft3\nleft4", "Right", 0.5)
Created on 2020-06-22 by the reprex package (v0.3.0)
There are two issued with mergeDesc()
in the latest develop version:
rgroup
and n.rgroup
are specified.rgroup
title line, when rgroup
and n.rgroup
are specified. It would look nicer if all p-values were shown on the rgroup
title line.Example below:
library(Gmisc)
data("mtcars")
cars_missing <- mtcars
cars_missing$mpg[3] <- NA
# p-values are not displayed when rgroup and n.rgroup are specified
mergeDesc(getDescriptionStatsBy(x = cars_missing$mpg,
by = cars_missing$cyl,
statistics = TRUE),
htmlTable_args = list(rgroup = c("Gas"),
n.rgroup = 2))
# p-values are displayed when rgroup and n.rgroup are not specified
mergeDesc(getDescriptionStatsBy(x = cars_missing$mpg,
by = cars_missing$cyl,
statistics = TRUE))
# p-values are displayed for one-line summaries only when rgroup and n.rgroup are specified
# but in the wrong place - they should be on the rgroup title line, not on the summary line
mergeDesc(getDescriptionStatsBy(x = cars_missing$mpg,
by = cars_missing$cyl,
statistics = TRUE),
getDescriptionStatsBy(x = cars_missing$disp,
by = cars_missing$cyl,
statistics = TRUE),
htmlTable_args = list(rgroup = c("Gas", "Displacement"),
n.rgroup = c(2, 1)))
# p-values are displayed for both summaries when rgroup and n.rgroup are not specified
mergeDesc(getDescriptionStatsBy(x = cars_missing$mpg,
by = cars_missing$cyl,
statistics = TRUE),
getDescriptionStatsBy(x = cars_missing$disp,
by = cars_missing$cyl,
statistics = TRUE))
4 | 6 | 8 | P-value | |
---|---|---|---|---|
Gas | ||||
Mean (SD) | 27.1 (±4.6) | 19.7 (±1.5) | 15.1 (±2.6) | |
Missing | 1 (9.1%) | 0 (0%) | 0 (0%) |
4 | 6 | 8 | P-value | |
---|---|---|---|---|
cars_missing$mpg | < 0.0001 | |||
Mean (SD) | 27.1 (±4.6) | 19.7 (±1.5) | 15.1 (±2.6) | |
Missing | 1 (9.1%) | 0 (0%) | 0 (0%) |
4 | 6 | 8 | P-value | |
---|---|---|---|---|
Gas | ||||
Mean (SD) | 27.1 (±4.6) | 19.7 (±1.5) | 15.1 (±2.6) | |
Missing | 1 (9.1%) | 0 (0%) | 0 (0%) | |
Displacement | ||||
cars_missing$disp | 105.1 (±26.9) | 183.3 (±41.6) | 353.1 (±67.8) | < 0.0001 |
4 | 6 | 8 | P-value | |
---|---|---|---|---|
cars_missing$mpg | < 0.0001 | |||
Mean (SD) | 27.1 (±4.6) | 19.7 (±1.5) | 15.1 (±2.6) | |
Missing | 1 (9.1%) | 0 (0%) | 0 (0%) | |
cars_missing$disp | 105.1 (±26.9) | 183.3 (±41.6) | 353.1 (±67.8) | < 0.0001 |
When using a statistical sig limit threshold for a continuous variable in getDescriptioStatsBy, The Pvalue shows as < 0.0001 instead of <0.0001. Same with the ±, probably indicating bugs in the html code
getDescriptionStatsBy(mtcars$wt, by=mtcars$am, statistics = TRUE) %>% htmlTable(.)
install.packages("Gmisc")
library(Gmisc)
Loading required package: htmlTable
Warning messages:
1: package ‘Gmisc’ was built under R version 3.1.2
2: package ‘htmlTable’ was built under R version 3.1.2
?htmlTable
starting httpd help server ... done
output <- matrix(1:4,
ncol=2,
dimnames = list(list("Row 1", "Row 2"),
htmlTable(output)list("Column 1", "Column 2")))
Error in htmlTable.default(output) : could not find function "%<>%"
Updated to 3.1.2 and same issue. Replicated on Mac OSX Mavericks and Windows Server R2 in both base R and Rstudio 098.1091.
Thanks
Is it possible to have mixed font styles in a single boxGrob? e.g. something like
Group 1 (N = 10)
This would be a really useful feature...
Thanks, Alan
I checked the getSvdMostInfluential() function after getting different results in the data output and the plot.
I found that it calls Gmisc:::prData2Plot(). It defines a function within a lapply for building the plot x-axis labels (line 128 of getSvdMostInfluential.R).
I believe that the line:
ret <- paste(c(varnames[1:(prGetMaxNo2Print() - 1)],
sprintf("+ %d other", length(x) + 1 - prGetMaxNo2Print())), collapse = "\n")
should be:
ret <- paste(c(varnames[x[1:(prGetMaxNo2Print() - 1)]],
sprintf("+ %d other", length(x) + 1 - prGetMaxNo2Print())), collapse = "\n")
Otherwise, it just prints the variable names in order, not the ones corresponding to that group.
Greetings!
Hi! Great package for flow charts, but how can you connect boxes after having spread them by e.g. spreadVertical?
library(Gmisc)
#> Lade nötiges Paket: Rcpp
#> Lade nötiges Paket: htmlTable
library(grid)
library(magrittr)
grid.newpage()
b1 <- boxGrob(label = "bla",
y = .4, x = .5)
b2 <- boxGrob(label = "foo",
y = .2, x = .5)
alignHorizontal(b1, b1, b2) %>%
spreadVertical(.from = .8, .to = .2)
connectGrob(b1, b2)
Created on 2022-07-04 by the reprex package (v2.0.1)
Hello,
I have some factors with some categories with 0 counts. How can I make describeFactors to show all values including 0's
Thanks
As discussed in the other issue #56 . The boxGrob
function only draw round cornered rectangle, add an option to allow selection of the rectangle shape.
Add a parameters to boxGrob
, so user can choose from rectGrob
and roundrectGrob
.
I keep getting the following warnings in RStudio:
Warning messages:
1: In readLines(input, encoding = "UTF-8") :
incomplete final line found on '/usr/local/lib/R/site-library/Gmisc/rmarkdown/templates/STROBE_v4_docx/template.yaml'
2: In readLines(input, encoding = "UTF-8") :
incomplete final line found on '/usr/local/lib/R/site-library/Gmisc/rmarkdown/templates/CONSORT_v2010_docx/template.yaml'
I'm currently seeing
checking R code for possible problems ... NOTE
getDescriptionStatsBy: no visible global function definition for
‘label<-’
checking Rd cross-references ... NOTE
Package unavailable to check Rd xrefs: ‘rmeta’
One nice thing about do.call is, one can do things like:
> do.call(order, datasets::iris)
However, this does not work:
> fastDoCall(order, datasets::iris)
Error in rep(value, length.out = nrows) :
attempt to replicate an object of type 'closure'
So my suggestion is to make it work with data frames (since they are lists), or explicitly disallow using data.frames with a more informative error message.
Thanks!
Hi Max,
I regularly run into the following situation with clinical trial data:
getDescriptionStatsBy
that generates output with length > 1mergeDesc
and lapply
to run this function over a number of observationsThere are two problems with this solution:
n.rgroup
should be, and causes inconsistent table layout.The first case is relatively easy. I've written some code to deal with it that won't change anything in existing calls to getDescriptionStatsBy
. Would you accept a PR for this?
I am not sure how you would like the function to react in case 2. IMO, it should return a named vector with indicators for empty values. This named vector would be a new argument to getDescriptionStatsBy
. The default value of this empty vector would be NULL so as not to disturb existing code. What do you think?
Thanks,
Peter.
Toy example:
# datasets
trial <- data.frame(visit = sort(rep(c("randomisation", "week1", "week2", "week3"), 5)),
arm = sort(rep(c("control", "treatment"))),
outcome = rnorm(40))
trial_missing_first <- trial[!((trial$visit == "randomisation") & (trial$arm == "control")),]
trial_missing_second <- trial[!((trial$visit == "randomisation") & (trial$arm == "treatment")),]
trial_missing_both <- trial[!(trial$visit == "week3"),]
# toy function
descriptive_function <- function(x, ...) {
result <- c(describeMean(x, ...),
describeMedian(x, ...))
return(result)
}
# no missingness - no problems
(out <- mergeDesc(lapply(levels(trial$visit), function(x)
getDescriptionStatsBy(x = trial$outcome[trial$visit == x],
by = trial$arm[trial$visit == x],
continuous_fn = descriptive_function)),
htmlTable_args = list(rgroup = levels(trial$visit),
n.rgroup = rep(2, 4))))
# missingness in first column -> error.
(out <- mergeDesc(lapply(levels(trial_missing_first$visit), function(x)
getDescriptionStatsBy(x = trial_missing_first$outcome[trial_missing_first$visit == x],
by = trial_missing_first$arm[trial_missing_first$visit == x],
continuous_fn = descriptive_function)),
htmlTable_args = list(rgroup = levels(trial_missing_first$visit),
n.rgroup = rep(2, 4))))
# missingness in second column -> no error
(out <- mergeDesc(lapply(levels(trial_missing_second$visit), function(x)
getDescriptionStatsBy(x = trial_missing_second$outcome[trial_missing_second$visit == x],
by = trial_missing_second$arm[trial_missing_second$visit == x],
continuous_fn = descriptive_function)),
htmlTable_args = list(rgroup = levels(trial_missing_second$visit),
n.rgroup = rep(2, 4))))
# missingness in both columns -> problems with n.rgroup, inconsistent table layout
(out <- mergeDesc(lapply(levels(trial_missing_both$visit), function(x)
getDescriptionStatsBy(x = trial_missing_both$outcome[trial_missing_both$visit == x],
by = trial_missing_both$arm[trial_missing_both$visit == x],
continuous_fn = descriptive_function)),
htmlTable_args = list(rgroup = levels(trial_missing_both$visit),
n.rgroup = rep(2, 4))))
There is a typo in the function getPvalAnova. I think you meant to write 'variable' instead of 'vaiable'. This causes the function 'getDescriptionStatsBy' to throw an error when using the option statistics = TRUE.
I really like your excellent package!! Thanks for your excellent work.
But recently, I was trying to use this package to make a table and it contain some Chinese characters, but I found it fails to display the characters.
Thank you so much for your help!!!!!!😸
Hi, thanks for making Gmisc available.
I am using tags like or in cell of htmlTable for specific formatting of just part of the cell.
In the last version (0.6.4), HTML tags in the data cells get changed to latex code, is that the expected behavior?
This does not occur in the column or row headings.
Thanks.
Hi,
Background
I am using this package to create consort diagram. If there are lots of box nodes, the plot will be cropped. Like some times I get negative y value for the box if I want to align the boxes to avoid any overlaps.
Issue
One solution I find is to change the text size by changing the cex to lower value. But the box size stayed the same. I realized that the grobHeight(txt)
and grobWidth(txt)
will return 1grobheight
and 1grobwidth
. The box size actually stayed the same.
Possible solution
If I change it to convertUnit(grobHeight(txt), "mm")
and convertUnit(grobWidth(txt), "mm")
the box size will change automatically.
Can this be changed? Or should I submit a pull request? Many thanks.
Best,
Alimu
(Cross-posting from https://stackoverflow.com/questions/63944420/choose-font-for-transition-diagram-in-gmisc)
How can one change the text font in a transition diagram created with the GMisc package in R?
I can get 2% of the way there as follows:
library(grid)
library(Gmisc)
grid.newpage()
txt <-
"Just a plain box"
windowsFonts(
A=windowsFont("TT Courier New"),
B=windowsFont("TT Helvetica"),
C=windowsFont("TT Montserrat")
)
boxGrob(txt, txt_gp = getOption("boxGrobTxt", default = gpar(fontfamily = "A")))
boxGrob(txt, txt_gp = getOption("boxGrobTxt", default = gpar(fontfamily = "B")))
boxGrob(txt, txt_gp = getOption("boxGrobTxt", default = gpar(fontfamily = "C")))
which generates the single box in the three different fonts successively.
I'd be grateful for a way to achieve the same thing globally when rendering a transition plot created as in the vignette, i.e.,
library(Gmisc)
transitions <- table(data$Charnley_class, data$Charnley_class_1yr) %>%
getRefClass("Transition")$new(label=c("Before surgery", "1 year after"))
transitions$render()
Yesterday I created a Consort diagram for a clinical trial that I am reporting. Fortunately I saved a copy of the printout (attached).
CIT Consort diagram..docx
This AM I updated R to 4.03 and reran the r program below:
# CIT long-term outcomes Consort diagram
library(Gmisc, quietly = TRUE)
library(glue, quietly = TRUE)
library(htmlTable, quietly = TRUE)
library(grid, quietly = TRUE)
library(magrittr, quietly = TRUE)
CIT07 <- boxGrob(glue("Transplanted in", "CIT-07, n = 48", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.92, x = 0.14)
EarlyX07 <- boxGrob(glue("Failed, n = 2", "Withdrew*, n = 5",.sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.78, x = 0.38)
Comp07 <- boxGrob(glue("Completed CIT-07", "n = 48", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.64, x = 0.14)
Not8_07 <- boxGrob(glue("Exited CIT*, n= 5", "n = 48", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.50, x = 0.38)
CIT8_07 <- boxGrob(glue("Entered CIT-08", "n = 5", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.36, x = 0.14)
EarlyX8_07 <- boxGrob(glue("Failed, n = 4", "Withdrew*, n = 3", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.22, x = 0.28)
Complete07 <-boxGrob(glue("Completed CIT-08", "n = 5", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = .08, x = 0.14)
CIT06 <- boxGrob(glue("Transplanted", "in CIT-06, n = 24", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.92, x = 0.86)
EarlyX06 <- boxGrob(glue("Failed, n = 5", "Withdrew*, n = 5",.sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.78, x = 0.64)
Comp06 <- boxGrob(glue("Completed CIT-06", "n = 3", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.64, x = 0.86)
Not8_06 <- boxGrob(glue("Exited CIT*, n= 5", "n = 48", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.50, x = 0.64)
CIT8_06 <- boxGrob(glue("Entered CIT-08", "n = 48", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.36, x = 0.70)
EarlyX8_6 <- boxGrob(glue("Failed, n = 4", "Withdrew*, n = ",.sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.22, x = 0.55)
CompIn06 <- boxGrob(glue("Completed CIT", "in CIT-06, n = 5", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.08, x = 0.86)
CompIn08 <- boxGrob(glue("Completed CIT", "in CIT-08, n = 5", .sep = "\n"),
txt_gp = gpar(fontsize = 11), width = .2, height = .08,
y = 0.08, x = 0.54)
windows(height = 9, width = 6.5)
CIT07; EarlyX07; Comp07; Not8_07; CIT8_07; EarlyX8_07; Complete07
CIT06; EarlyX06; Comp06; Not8_06; CIT8_06; EarlyX8_6; CompIn06; CompIn08
connectGrob(CIT07, Comp07, type = 'N')
connectGrob(CIT07, EarlyX07, type = 'L')
connectGrob(Comp07, CIT8_07, type = 'N')
connectGrob(Comp07, Not8_07, type = 'L')
connectGrob(CIT8_07, Complete07, type = 'N')
connectGrob(CIT8_07, EarlyX8_07, type = 'L')
connectGrob(CIT06, Comp06, type = 'N')
connectGrob(Comp06, CompIn06, type = 'N')
connectGrob(CIT06, EarlyX06, type = 'L')
connectGrob(Comp06, Not8_06, type = 'L')
connectGrob(Comp06, CIT8_06, type = 'L')
connectGrob(CIT8_06, EarlyX8_6, type = 'N')
connectGrob(CIT8_06, CompIn08, type = 'L')
The boxGrobs are plotting correctly, but the connectGrobs are messed up. Repeatable on two Windows 10 desktops.
Something in the new version of R is messing up the mapping or something. I suspect that this is not your bug, but you folks will probably be stuck with fixing it. Meanwhile I may have to drop back to R 4.02. Many thanks for any help you can give me.
Larry Hunsicker
I am practicing using the code on the project page https://cran.r-project.org/web/packages/Gmisc/vignettes/transitionPlot.html and I found that anytime I make a small change to the parameters and try plotting the transition plot again, it overlays on previous one instead of creating a new plot on a new pane (see screenshot attached). I doubt this is a problem with Rstudio or R version as I tried plotting multiple plots using ggplot package and some base R plotting functions and each of them come up in a new plot pane.
In case you need it:
Rstudio: Version 1.1.453
R 3.5.1 GUI 1.70 El Capitan build (7543)
MAC OS High Sierra Version 10.13.1
Thanks for a great package.
Given the native pipe, |>
, is now used in several places in the code, do you need to update the DESCRIPTION
file to reflect the version of R where that was introduced, i.e.,
Depends:
R (>= 3.2.0),
needs to be bumped up to
Depends:
R (>= 4.1.0),
Error when header_count
is character
data(mtcars)
mtcars$am <- factor(mtcars$am, levels=0:1, labels=c("Automatic", "Manual"))
Hmisc::label(mtcars$am) <- "Transmission"
set.seed(666)
mtcars$col <- factor(sample(c("red", "black", "silver"),
size=NROW(mtcars), replace=TRUE))
Gmisc::getDescriptionStatsBy(
x=mtcars$col,
by=mtcars$am,
header_count = "(n = %s)", # custom header
add_total_col = TRUE,
statistics = TRUE
)
#> Error in !header_count: invalid argument type
I'm on it, so expect a PR soon.
The option use_units = 'name' does not work as documented, probably because of line 467 -
if(use_units)
It should be replaced by something like
if(isTRUE(use_units))
some tests:
use_units <- TRUE
if(use_units) print('success')
use_units <- FALSE
if(use_units) print('success')
use_units <- 'name'
if(use_units) print('success')
if(isTRUE(use_units)) print('success')
header_count in getDescriptionStatsBy cannot be a string because of the construct missing(header_count) || !header_count. If it's a string, the latter fails and returns an error "invalid argument type"
I get an error when I try to set the arrows in a transition plot proportional to the boxes.
library(Gmisc)
transMatrix <- as.table(matrix(c(16, 4, 16, 64),ncol=2,byrow=T))
transitions <- transMatrix %>%
getRefClass("Transition")$new(label=c("Step 1", "Step 2"))
transitions$render()
Until here it works.
However, when I set the arrows to be proportional to the boxes, I get an error:
transitions$lwd_prop_type = "box"
transitions$render()
[.default`(trnstn_set, row, ) : invalid subscript type 'closure'
lwd_prop_type="all"
and lwd_prop_type="set"
work.
Is there an easy way to fix this or did I do something wrong? Thank you.
Dear Max,
I'm trying to install your package un Rstudio using the GUI and searching it in the search box. I cannot find it in the CRAN repository unfortunately. Also when downloading it from here (https://cran.r-project.org/web/packages/Gmisc/index.html) and then installing it from a file on my computer, I get errors.
How do I install your package from the CRAN repository?
Best,
Anne
Hi,
I am a heavy user of Gmisc: getDescriptionStatsBy.
I found that I cannot get headder_count work by adding "No. %s patients" into the following function:
getTable1Stats <- function(x, digits = 0, ...){
getDescriptionStatsBy(x = x, digits = digits,
header_count = "No. %s patients", #<--- this is where I inserted the format
continuous_fn = describeMedian,
factor_fn = describeFactors,
by = data$technical_success,
#show_all_values = TRUE,
NEJMstyle = FALSE,
useNA = "no",
add_total_col = TRUE,
#default_ref = "Yes",
...)
}
Did I make anything wrong?
Because the script ended abnormally with: error in type of parameter.
Hi,
I am working on a use case with the Gmisc package. I am looking for an option to export the zoomed plot through code. The normal export option in shrinking the image. Ideally a command line in R that can save the object as a jpg/png is needed. Any assistance to get this done would be great. Need to make the final plot an object so that it can be exported, but without shrinking the image. The following code is from an example in CRAN. However the image I have created is bigger and the right scale is coming only while viewing the zoomed version.
grid.newpage()
# Initiate the boxes that we want to connect
side <- boxPropGrob("Side", "Left", "Right",
prop=.3,
x=0, y=.9,
bjust = c(0,1))
start <- boxGrob("Top",
x=.6, y=coords(side)$y,
box_gp = gpar(fill = "yellow"))
bottom <- boxGrob("Bottom", x=.6, y=0,
bjust="bottom")
sub_side_left <- boxGrob("Left",
x = coords(side)$left_x,
y = 0,
bjust = "bottom")
sub_side_right <- boxGrob("Right",
x = coords(side)$right_x,
y = 0,
bjust = "bottom")
odd <- boxGrob("Odd\nbox",
x=coords(side)$right,
y=.5)
odd2 <- boxGrob("Also odd",
x=coords(odd)$right +
distance(bottom, odd, type="h", half=TRUE) -
unit(2, "mm"),
y=0,
bjust = c(1,0))
exclude <- boxGrob("Exclude:\n - Too sick\n - Prev. surgery",
x=1, y=coords(bottom)$top +
distance(start, bottom,
type="v", half=TRUE),
just="left", bjust = "right")
# Connect the boxes and print/plot them
connectGrob(start, bottom, "vertical")
connectGrob(start, side, "horizontal")
connectGrob(bottom, odd, "Z", "l")
connectGrob(odd, odd2, "N", "l")
connectGrob(side, sub_side_left, "v", "l")
connectGrob(side, sub_side_right, "v", "r")
connectGrob(start, exclude, "-",
lty_gp = gpar(lwd=2, col="darkred", fill="darkred"))
# Print the grobs
start
bottom
side
exclude
sub_side_left
sub_side_right
odd
odd2
transitionPlot.R
is cool. I prefer it to original Sankey, in which sometimes the bands are not readable.
I wonder could it be possible to control the shadow of the boxes? I personally like my plots to be minimalist, or without 3D effect.
Thanks.
Hi Max,
I get these warnings, both in master and develop:
> library(Gmisc)
Loading required package: Rcpp
Loading required package: htmlTable
Warning messages:
1: In readLines(input, encoding = "UTF-8") :
incomplete final line found on 'C:/Users/xxxx/Documents/R/win-library/3.4/Gmisc/rmarkdown/templates/CONSORT_v2010_docx/template.yaml'
2: In readLines(input, encoding = "UTF-8") :
incomplete final line found on 'C:/Users/xxxx/Documents/R/win-library/3.4/Gmisc/rmarkdown/templates/STROBE_v4_docx/template.yaml'
This is under version 3.4.2 (2017-09-28), x86_64-w64-mingw32/x64 (64-bit)
Maybe the EOL character is missing?
/Peter
I've never had problems rendering tables in markdown documents until recently, and I can't quite figure out if this is happening due to a knitr, rmarkdown, or R3.1.2 update. Do you see anything like this as well?
If I have a .Rmd with
{r, results='asis'}
library("Gmisc")
htmlTable(head(mtcars))
I get the results
Subbing out all the tab characters in table_str
renders it properly
gsub("\t", " ", x)
but it wasn't an issue before. Can you reproduce this?
Message from Kurt Hornik:
These all show check problems on the Debian check systems caused by
attempts to write to the user library to which all packages get
installed before checking (and which now is remounted read-only for
checking).Having package code which is run as part of the checks and attempts to
write to the user library violates the CRAN Policy'sPackages should not write in the user’s home filespace (including
clipboards), nor anywhere else on the file system apart from the R
session’s temporary directory (or during installation in the location
pointed to by TMPDIR: and such usage should be cleaned up).Hence, please update your package(s) as quickly as possible to no longer
(attempt to) write to the user library (including, of course, the
location where the package itself was installed to).
Hi,
I always get these warnings when loading your package:
1: In readLines(input, encoding = "UTF-8") :
incomplete final line found on '/usr/local/lib/R/site-library/Gmisc/rmarkdown/templates/STROBE_v4_docx/template.yaml'
2: In readLines(input, encoding = "UTF-8") :
incomplete final line found on '/usr/local/lib/R/site-library/Gmisc/rmarkdown/templates/CONSORT_v2010_docx/template.yaml'
getDescriptionStatsBy throws error when useNA = "no" options is used for some variables.
It worked fine in version 0.6.7 but in version 1.0, the warning is that "there is a discrepancy in the number of rows in the total table and the by results: 1 total vs 3 results." I'm expecting 3 in total as well and cannot figure out why total = 1.
A number of links in transitionPlot.Rmd and transition-class.Rmd are routed through the Karolinska proxy server (proxy.kib.se). Some of these appear to link to the wrong target, too: they refer to the diagram package and data-ink ratio but all point to the article.
Hi Max,
I ran into this when using a custom function for prop_fn. If a user specifies their own function for prop_fn with the show_all_values = TRUE option the user-specified function is overridden by describeFactors(). This is caused by line 272-273 of getDescriptionStatsBy.R (develop branch).
I can do a PR tonight if you are interested.
with kind regards
Peter.
I get this message at a transitionPlot, although the rest of the arguments of the function work well. Any clue what might be going on? Thanks
Am trying to generate a transition plot on a dataset I have.
Dataset has 10 columns. Level1 to Level10.
Level1 has 21 unique levls of observations, level2 column has 21,level3 has 17, level4 has 15 and finally Level9 has 2 unique levels. All the missing information was given "None" as label.
I dont want to have boxes and arrows pointing to "None". Can you please help me with the code.
This is the code used
transitions <- table(data$Level1,data$Level2) %>%
getRefClass("Transition")$new(label=c("1st Iteration", "2nd Iteration"))
transitions$box_width = 0.25;
transitions$box_label_cex = 0.7;
transitions$arrow_type = "simple";
transitions$arrow_rez = 300;
table(data$Level2,data$Level3) %>% transitions$addTransitions(label = '3rd Iteration')
table(data$Level3,data$Level4) %>% transitions$addTransitions(label = '4th Iteration')
table(data$Level4,data$Level5) %>% transitions$addTransitions(label = '5th Iteration')
table(data$Level5,data$Level6) %>% transitions$addTransitions(label = '6th Iteration')
table(data$Level6,data$Level7) %>% transitions$addTransitions(label = '7th Iteration')
table(data$Level7,data$Level8) %>% transitions$addTransitions(label = '8th Iteration')
table(data$Level8,data$Level9) %>% transitions$addTransitions(label = '9th Iteration')
transitions$max_lwd <- unit(.05, "npc")
transitions$render()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.