vertesy / ggexpress Goto Github PK
View Code? Open in Web Editor NEWggExpress is the fastest way to create, annotate and and save plots in R.
Home Page: https://vertesy.github.io/ggExpress
License: GNU General Public License v3.0
ggExpress is the fastest way to create, annotate and and save plots in R.
Home Page: https://vertesy.github.io/ggExpress
License: GNU General Public License v3.0
function(vec, ext = "pdf", plot = TRUE, save = TRUE, mdlink = TRUE
, hline = F, filtercol = 1
, xlab.angle = 90, xlab = F
, w = 5, h = w, ...) {
plotname <- as.character(substitute(vec))
...
qbarplot
should auto-guess the width based on input length qqqParsePlotname(vec, suffix)
In
qbarplot <- function(vec, ext = "pdf", plot = TRUE
, suffix = NULL
, plotname = qqqParsePlotname(vec, suffix)
# , title = F
, save = TRUE, mdlink = FALSE
, hline = F, filtercol = 1
, palette_use = 'jco', col = as.character(1:3)[1]
, xlab.angle = 90, xlab = F
, logY = F
, label = NULL
, max.names = 50
, limitsize = FALSE
, w = qqqAxisLength(vec), h = 5, ...) {
(of connected functions)
flowchart LR
qviolin(qviolin) --> qqqList.2.DF.ggplot(qqqList.2.DF.ggplot)
qviolin(qviolin) --> qqSave(qqSave)
qviolin(qviolin) --> qMarkdownImageLink(qMarkdownImageLink)
qvenn(qvenn) --> qqSave(qqSave)
qvenn(qvenn) --> qMarkdownImageLink(qMarkdownImageLink)
qstripchart(qstripchart) --> qqqList.2.DF.ggplot(qqqList.2.DF.ggplot)
qstripchart(qstripchart) --> qqSave(qqSave)
qstripchart(qstripchart) --> qMarkdownImageLink(qMarkdownImageLink)
qscatter(qscatter) --> qqSave(qqSave)
qscatter(qscatter) --> qMarkdownImageLink(qMarkdownImageLink)
qpie(qpie) --> qqqNamed.Vec.2.Tbl(qqqNamed.Vec.2.Tbl)
qpie(qpie) --> qqSave(qqSave)
qpie(qpie) --> qMarkdownImageLink(qMarkdownImageLink)
qhistogram(qhistogram) --> qqqNamed.Vec.2.Tbl(qqqNamed.Vec.2.Tbl)
qhistogram(qhistogram) --> qqSave(qqSave)
qhistogram(qhistogram) --> qMarkdownImageLink(qMarkdownImageLink)
qdensity(qdensity) --> qqqNamed.Vec.2.Tbl(qqqNamed.Vec.2.Tbl)
qdensity(qdensity) --> qqSave(qqSave)
qdensity(qdensity) --> qMarkdownImageLink(qMarkdownImageLink)
qboxplot(qboxplot) --> qqqList.2.DF.ggplot(qqqList.2.DF.ggplot)
qboxplot(qboxplot) --> qqSave(qqSave)
qboxplot(qboxplot) --> qMarkdownImageLink(qMarkdownImageLink)
qbarplot.df(qbarplot.df) --> qqSave(qqSave)
qbarplot.df(qbarplot.df) --> qMarkdownImageLink(qMarkdownImageLink)
qbarplot(qbarplot) --> qqqNamed.Vec.2.Tbl(qqqNamed.Vec.2.Tbl)
qbarplot(qbarplot) --> qqSave(qqSave)
qbarplot(qbarplot) --> qMarkdownImageLink(qMarkdownImageLink)
created by convert_igraph_to_mermaid()
Description
color argument in qhistogram is not working
condiitions 2 and 3 seem nonsense:
(prob from qbarplot)
df[["colour"]] <- if (vline & filtercol != 0) {
if (filtercol == 1 ) (df$"value" > vline) else if (filtercol == -1 ) (df$"value" < vline)
} else if (length(col) == length(vec)) {
as.character(col)
} else {
as.character(rep(col, length(vec))[1:length(vec)])
}
scriptname
) and potentially the author to the title field of the output .pdf
files. It was not the case when saving as .png
.ggExpressDev
See title
inside ww.dev.copy
dev.copy2pdf(
file = ww.FnP_parser(fname_, "pdf"),
width = w_,
height = h_,
title = ww.ttl_field(fname_)
Description
qqqCovert.named.vec2tbl fails when strip.too.many.names = F
df <- qqqCovert.named.vec2tbl(namedVec = vec, strip.too.many.names = F)
Error in print.default("Vector has", thr, "+ names. Can mess up auto-color legends.") :
invalid printing digits 50
Description
file.edit("~/GitHub/Packages/ggExpress/R/ggExpress.R")
my_tibble <- tibble(
Column_1 = c("A", "A", "A", "B", "C", "C"),
Column_2 = c("X", "Y", "Y", "Z", "X", "Z")
)
freq_table <- my_tibble %>% count(Column_1, Column_2)
qbarplot.df(freq_table)
qbarplot.df(my_tibble)
example_tibble <- tibble(
ID = rep(c("A", "B", "C"), times = 4),
Time = rep(1:4, each = 3),
Value = rnorm(12)
)
qbarplot.df(example_tibble)
> qbarplot.df(example_tibble)
Error in median(as.numeric(df[, y])) :
'list' object cannot be coerced to type 'double'
Trying to install ggExpress so that I can install Seurat.utils and running into the following error:
devtools::install_github(repo = "vertesy/ggExpress@HEAD")
Downloading GitHub repo vertesy/ggExpress@HEAD
✓ checking for file ‘/tmp/Rtmpu9c30N/remotes19a625b7236/vertesy-ggExpress-ef9bab4/DESCRIPTION’ ...
─ preparing ‘ggExpress’:
✓ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘ggExpress_0.2.2.tar.gz’
Installing package into ‘/sbgenomics/workspace/rpkgs’
(as ‘lib’ is unspecified)
Description
both_pc_and_value argument in qpie seem not working
xvec <- c("A"=12, "B"=29);
qpie(vec = xvec)
qpie(vec = xvec, both_pc_and_value = T)
Description
qbarplot seem to add up data in the final element.
It seem to maybe come from qqqCovert.named.vec2tbl
Expected Behavior
Should strip names, but not adding up values.
datX = c(A.1 = 15273817120.75, A.2 = 19748042499.75, A.3 = 19015562583.97, A.4 = 19539107256.48, A.5 = 20293595960.89, A.6 = 18401588363.56, A.7 = 18876623322.12, A.8 = 20113344495.41, A.9 = 19759801754.07, A.10 = 19862305126.29, B.1 = 14049263285.29, B.2 = 15310874767.7, B.3 = 13316238905.88, B.4 = 13053793265.22, B.5 = 12451837184.56, B.6 = 15095732257.66, B.7 = 13793883930.1, B.8 = 14145915911.97, B.9 = 14029136875.07, B.10 = 16434420425.09, C.1 = 16634725276.67, C.2 = 17635189764.07, C.3 = 18453442284.71, C.4 = 18140879520.46, C.5 = 19454822015.85, C.6 = 19472830899.79, C.7 = 19187828858.17, C.8 = 19290220121.02, C.9 = 19176960564.72, C.10 = 18101441453.02, D.1 = 16194435630.05, D.2 = 18078756773.13, D.3 = 17579176095.34, D.4 = 16857272399.08, D.5 = 17902504889.1, D.6 = 17689611098.42, D.7 = 17892178766.36, D.8 = 17819751385.79, D.9 = 16896316453.25, D.10 = 17843222873.72, E.1 = 19266947287.15, E.2 = 19102158394.34, E.3 = 18135419322.44, E.4 = 18720949164.04, E.5 = 19172455475.47, E.6 = 17089109522.67, E.7 = 19203272180.69, E.8 = 19543017029.51, E.9 = 17488648870.63, E.10 = 18433494529.85, F.1 = 16373913388.65, F.2 = 17247845170.57, F.3 = 17309605641.54, F.4 = 16811631542.41, F.5 = 17734956810.56, F.6 = 17629744406.91, F.7 = 17552351271.36, F.8 = 17887451319.71, F.9 = 17912108211.29, F.10 = 18339746215.46, G.1 = 13032074439.62, G.2 = 13268056651.77, G.3 = 12768107933.15, G.4 = 11318557947.43, G.5 = 13112409433.13, G.6 = 12970230567.49, G.7 = 12447675596.99, G.8 = 11066276951.24, G.9 = 11787443223.6, G.10 = 14026544366.27, H.1 = 21877575254.63, H.2 = 24743269000.6, H.3 = 23873349116.16, H.4 = 25843702092.69, H.5 = 24832172670.89, H.6 = 26174812828.44, H.7 = 25820908847.56, H.8 = 24123991349.34, H.9 = 26286380503.78, H.10 = 1765156596.59, I.1 = 22004381857.62, I.2 = 19878260460.73, I.3 = 22679932183.01, I.4 = 21000909188.35, I.5 = 23336329575.16, I.6 = 23889551306.53, I.7 = 23551824810.83, I.8 = 21266124403.33, I.9 = 23571944492.02, I.10 = 1460005444.33, J.1 = 20887643832.89, J.2 = 22482078231.65, J.3 = 22819414495.48, J.4 = 24019122823.56, J.5 = 23243883898.4, J.6 = 22590511082.91, J.7 = 23752435598.41, J.8 = 22748121492.62, J.9 = 19315053455.04, J.10 = 1259362111.49, K.1 = 23540019932.29, K.2 = 24775818787.02, K.3 = 20386348553.98, K.4 = 25039316068.69, K.5 = 20917657564.64, K.6 = 20289950682.21, K.7 = 25211705926.88, K.8 = 23043947654.76, K.9 = 24970635486.15, K.10 = 1291511169.53, L.1 = 16237995863.11, L.2 = 20137547157.36, L.3 = 9704396265.18, L.4 = 19494896522.97, L.5 = 20357174248.84, L.6 = 20501902989.71, L.7 = 20507997756.31, L.8 = 20224579660.29, L.9 = 20472644107.52, L.10 = 1429814856.84, M.1 = 17093855098.68, M.2 = 22708468267.65, M.3 = 17112070009.12, M.4 = 19340725263.25, M.5 = 19109316557.26, M.6 = 9152375748.16, M.7 = 11789601377.25, M.8 = 10044131051.83, M.9 = 15977978843.56, M.10 = 12057889990.24, N.1 = 14309581287.03, N.2 = 16252468032.82, N.3 = 6968983806.91, N.4 = 13877044327.23, N.5 = 14220131960.2, N.6 = 9820674445.55, N.7 = 13536157372.82, N.8 = 13098031419.04, N.9 = 12511073551.64, N.10 = 12412045225.81, O.1 = 19985770044.07, O.2 = 18697038222.58, O.3 = 17542698389.18, O.4 = 17771104040.35, O.5 = 16599569895.31, O.6 = 20143989602.36, O.7 = 14641182791.99, O.8 = 15069290758.51, O.9 = 13971684113.31, O.10 = 7719658618.26, P.1 = 15105992372.21, P.2 = 15618543642.25, P.3 = 16519924399.5, P.4 = 18341317197.64, P.5 = 19920739997.97, P.6 = 14681411340.91, P.7 = 17025792187.53, P.8 = 13852606495.48, P.9 = 15357227597.44, P.10 = 15597400318.06, Q.1 = 18073761261.9, Q.2 = 15269826705.96, Q.3 = 19992603326.46, Q.4 = 13523915647.89, Q.5 = 19302407210, Q.6 = 13750064354.38, Q.7 = 13816139874.54, Q.8 = 17878540640.13, Q.9 = 21338075539.85, Q.10 = 11137639240.29)
qbarplot(datX)
plotting functions need failsafes against too many categories (when you set x <- numeric value in qviolin, barplot, etc)
Similar to MarkdownReports::wstripchart_list()
violin + data points.
can be done using ggstripchart
Description
Suddenly error arose when using qbarplot( logY = TRUE)
Expected Behavior
Simple conversion to log scale - there are no zeros
On a totally normal vector:
refilter.assigned.to.cells.X
0 1 2 3 4 5 6 7 8 9 10 11 12 13
1534 1011 328 157 78 51 30 15 20 18 4 3 5 2
14 15 16 17 18 19 25 28 29 33 34
2 2 1 2 2 1 1 1 1 1 1
Buggy Behavior
Error in seq.default(min, max, by = by) : 'from' must be a finite number
It is commented in "R selective finite number error when applying log scale" that its because plot area expansion... but numbers seem to have no effect.
New functions
Description
in qbarplot()
, suffix
is added 2x file name, if defined
qbarplot(Nr.of.UVIs.per.cell, label = Nr.of.UVIs.per.cell, palette_use = "aaas"
, suffix = NewObj_names[i]
...
)
".../.../Nr.of.UVIs.per.cell.sc06.692__H9.sc06.692__H9.bar.pdf"
Error in qbarplot, inside if (mdlink & save) qMarkdownImageLink(fname)
NOT LOGGED: Log path and filename is not defined in path_of_report
Error in (MarkdownHelpers::llogit())(paste0("![", file_name, "]", "(", :
attempt to apply non-function
shistogram(Total.Starter.Expr.per.cell)
[1] 11
[1] 2222
[1] "/Users/abel.vertesy/Dropbox/Abel.IMBA/AnalysisD/Abel/CON/p2.v2020.11.premRNA./RabV.Filter/Total.Starter.Expr.per.cell.hist.pdf"
[1] 22222
shistogram <- function(vec, ext = "pdf", xlab = F, vline = F, plot = TRUE, ...) {
plotname <- as.character(substitute(vec))
if(isFALSE(xlab)) xlab = plotname
df <- qqCovert.hist(namedVec = vec)
p <- gghistogram(data = df, x = "value"
, title = plotname, xlab = xlab
, add = "median"
, color = "names", fill = "names"
, palette = 'jco', ...
) +
if (length(unique(df$"names")) == 1) theme(legend.position = "none")
if (vline) p <- p + geom_vline(xintercept = vline)
fname = kpp(plotname, "hist", ext)
print(11)
qqSave(ggobj = p, title = plotname, fname = fname)
print(1121)
# if (plot) p
}
# ------------------------------------------------------------------------------------------------
qqSave <- function(ggobj, ext =c("png", "pdf")[2], w =4, h = w
, title = F, fname = F, ...) {
if(isFALSE(title)) title = substitute(ggobj)
if(isFALSE(fname)) fname <- kpp(title, ext)
print(2222)
print(paste0(getwd(),"/", fname))
print(22222)
# cowplot::save_plot(plot = ggobj, filename = fname, base_height = w, base_width = h)
ggsave2(plot = ggobj, filename = fname, height = w, width = h)
}
Total.Starter.Expr.per.cell <- colSums(EXPR.XXgenes[genes.primary.cells, ])
shistogram(Total.Starter.Expr.per.cell)
qbarplot cannot handle Fill and Colour arguments separately
color = "colour", fill = "colour",
Expected Behavior
Name parsed from variable name e.g abc
Buggy Behavior
Name is the name of the param = vec
qqqParsePlotname <- function(string = "sadsad", suffix_tag= NULL) { # parse plot name from variable name and suffix
nm <- make.names((substitute(string)))
if (!is.null(suffix_tag) & !isFALSE(suffix_tag)) nm <- Stringendo::kpp(nm, suffix_tag)
print(11)
print(nm)
return(nm)
}
qpie <- function(vec, ext = "pdf", plot = TRUE, save = TRUE, mdlink = FALSE
, suffix = NULL
, plotname = FixPath() kpp(substitute(vec), suffix)
, LegendSide = T, LegendTitle = as.character(substitute(vec)), NoLegend = F
, pcdigits = 2, NamedSlices =F
, custom.order = F
# , custom.margin = F
, palette_use = 'jco'
, max.names = 50
, w = 5, h = w, ...) {
df <- qqqCovert.named.vec2tbl(namedVec = vec, thr = max.names)
nrCategories.DFcol1 <- length(unique(df[,1])); stopif( nrCategories.DFcol1 > 100)
pcX <- df$"value" / sum(df$"value")
labs <- paste(100 * signif (pcX, pcdigits), "%", sep = "")
if (NamedSlices) labs <- paste(df$names, "\n", labs)
print(df)
if (custom.order != F) df$'names' <- factor(df$'names', levels = custom.order)
p <- ggpubr::ggpie(data = df, x = "value", label = labs
, fill = "names", color = "white"
, title = plotname
, palette = palette_use, ...)
if (LegendSide) p <- ggpubr::ggpar(p, legend = "right", legend.title = LegendTitle)
# if (custom.margin) p <- p + theme(plot.margin = unit(custom.margin, "cm"))
# p <- if (NoLegend) p + NoLegend() else p
p <- if (NoLegend) p + theme(legend.position = "none", validate = TRUE) else p
fname = Stringendo::kpp(plotname, suffix, "pie", ext)
if (save) qqSave(ggobj = p, title = plotname, fname = fname, ext = ext, w = w, h = h)
if (mdlink & save) qMarkdownImageLink(fname)
if (plot) p
}
abc <- 1:3
qpie(abc)
df <- data.frame(
group = c("Male", "Female", "Children but not teenager"),
value = c(25, 25, 50))
ggpie(df, "value", label = "group")
Fixing margin does not help
ggobj +
theme(plot.margin = unit(c(1,1,1,1), "cm"))
Function qqSave()
gives the error
Error in grDevices::png(...) :
unused arguments (title = ...)
Description
Colors a pain to define in qbarplot.
You can't easily provide a color vector as in wbarplot()
if
statement.── Conflicts ─────────────────────────────────── ggExpress conflicts ──
x flag.nameiftrue() masks ggExpress::flag.nameiftrue()
x kpp() masks ggExpress::kpp()
Draw Venn or Euler diagramms with ggExpress
Alternative of MarkdownReports::wvenn()
From Trinker's Gist
if (!require("pacman")) install.packages("pacman")
pacman::p_load(dplyr, venneuler)
pacman::p_load_current_gh('trinker/textshape', 'thomasp85/ggforce')
x <- matrix(sample(0:4, 80, TRUE, c(.6, .1, .1, .1, .1)), ncol=4)
colnames(x) <- LETTERS[1:4]
euler_dat <- split(as.data.frame(x), c(T, F)) %>%
setNames( c('dog', 'cat')) %>%
lapply(function(x){ rownames(x) <- letters[1:10]; x}) %>%
lapply(function(x){
y <- venneuler(x)
data.frame(y$centers, diameters = y$diameters, labels = y$labels, stringsAsFactors = FALSE)
}) %>%
textshape::bind_list('animal')
euler_dat %>%
mutate(r = diameters/2) %>%
ggplot() +
geom_circle(aes(x0 = x, y0 = y, r = r, fill=labels), alpha = .5) +
facet_wrap(~animal) +
geom_text(aes(x = x, y = y, label = labels)) +
coord_fixed()
Output
Output
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.