Related
I am using the following code semPlot::semPaths to plot a lavaan model:
semPaths(object = fit,
what = "stand",
nCharNodes = 0,
layout = "tree",
fade = FALSE,
exoCov = FALSE,
residuals = FALSE,
intercepts = FALSE,
rotation = 2,
sizeMan = 5,
sizeLat = 10,
edge.label.cex = 1.5,
minimum=0.16,
allVars = FALSE,
equalizeManifests = FALSE,
fixedStyle = 2)
And this is the figure from the semPaths output:
I want to remove all the red paths on the y-indicators (i.e., red lines on the right-hand side of the model). What argument can I add to remove them? Thanks.
I have tried adding various arguments to the semPaths() code based on R documentation and previous stackoverflow queries. These additional arguments are removing different paths and numbers, except for the paths I want to remove. Most arguments are included in the current code.
Every time I try to look up how to use a function in R using the ? command, what I get is some semi-useful explanations, commands I don't understand, and some limited examples.
What I end up doing most of the time instead of using this function is googling the answers instead, which sometimes helps for nuanced questions, but just trying to understand a single package becomes a chore unless it happens to come up in a basics book I'm reading on R.
I tried looking up how to "read" the help section, but the best I could find was this Dummies page which didn't really help much more:
Dummies Page on Help in R.
The main issue I'm having is that I just dont understand the syntax portion. Here is an example:
semPaths(object, what = "paths", whatLabels, style, layout = "tree",
intercepts = TRUE, residuals = TRUE, thresholds = TRUE, intStyle = "multi",
rotation = 1, curve, curvature = 1, nCharNodes = 3, nCharEdges = 3, sizeMan = 5,
sizeLat = 8, sizeInt = 2, sizeMan2, sizeLat2, sizeInt2, shapeMan, shapeLat,
shapeInt = "triangle", ask, mar, title, title.color = "black", title.adj = 0.1,
title.line = -1, title.cex = 0.8, include, combineGroups = FALSE, manifests,
latents, groups, color, residScale, gui = FALSE, allVars = FALSE, edge.color,
reorder = TRUE, structural = FALSE, ThreshAtSide = FALSE, thresholdColor,
thresholdSize = 0.5, fixedStyle = 2, freeStyle = 1,
as.expression = character(0), optimizeLatRes = FALSE, inheritColor = TRUE,
levels, nodeLabels, edgeLabels, pastel = FALSE, rainbowStart = 0, intAtSide,
springLevels = FALSE, nDigits = 2, exoVar, exoCov = TRUE, centerLevels = TRUE,
panelGroups = FALSE, layoutSplit = FALSE, measurementLayout = "tree", subScale,
subScale2, subRes = 4, subLinks, modelOpts = list(mplusStd = "std"),
curveAdjacent = '<->', edge.label.cex = 0.6, cardinal = "none",
equalizeManifests = FALSE, covAtResiduals = TRUE, bifactor, optimPoints = 1:8 * (pi/4),
...)
What does any of this mean? All I can tell are that the stuff in "" is a possible use of a function, and thats about it. How do I explore more? For example, if I wanna find out all the potential styles for "layout" in this function, how do I look them up?
Hi to understand the information in the help you can follow the following steps,
Thee help is structured with some sections , Usage, Value, Details, References, Examples.
Usage: you have the syntax of the function and their arguments, the mandatory arguments are the ones with no values, ie in semPaths(object,...) object is a mandatory argument.
Arguments: You have the arguments that the function can take and their respective default values.
Examples: perhaps the most important section, where you have some possible usage of the function
References: other sources you may need to read to understand the logic or how the computations are being done.
You may also need to check the package documentation, there you may find more details, you can find this just by googling "package name" .pdf
When using dfSummary() from the "summarytools" package in Rmarkdown -file, I get Graph -part of the summary printed as plain ASCII despite the st_options(plain.ascii = FALSE). The correct graphs are printed in the /tmp -folder, but are not displayed in the html-file.
{r Summary, results='asis', echo=FALSE}
st_options(bootstrap.css = FALSE,
plain.ascii = FALSE,
style = "rmarkdown",
dfSummary.silent = TRUE)
st_css()
dfSummary(df_data, tmp.img.dir = "/tmp", valid.col = FALSE, graph.magnif = 0.75)
Summary from the code above gets printed like this:
How can I get the proper graphs (which are in the tmp-folder nice and shiny) included in the HTML file?
How can I get the proper graphs (which are in the tmp-folder nice and shiny) included in the html file?
According to the Dominic's vignette - "Recommendations for Using summarytools With Rmarkdown":
For dfSummary(), grid is recommended.
So, you may try following, using print() function:
```{r Summary, results = "asis", cache = FALSE}
base::print(summarytools::dfSummary(df_data,
valid.col = FALSE, # drop Valid column if redundant
style = "grid", # set style to “grid”
plain.ascii = FALSE,
graph.magnif = 0.75, # zoom factor (max = 1) for bar plots and histograms
tmp.img.dir = "./tmp"),
dfSummary.silent = TRUE, # Suppresses messages about temporary files
bootstrap.css = FALSE)
```
Or, if you prefer to declare st_options() first:
```{r Summary2, results = 'asis', echo = FALSE}
st_options(bootstrap.css = FALSE,
dfSummary.silent = TRUE)
st_css()
dfSummary(df_data,
valid.col = FALSE,
style = "grid",
plain.ascii = FALSE,
graph.magnif = 0.75,
tmp.img.dir = "./tmp")
```
Let us know if this is helpful.
Just add style="grid":
dfSummary(df_data, style = "grid", tmp.img.dir = "/tmp",
valid.col = FALSE, graph.magnif = 0.75)
The documentation is not clear enough on this point, it'll be fixed in the next version.
I often create large plots in RStudio which I save to PDF but would also like to partly show in the PDF knitr report.
Is there a way to create the full object then cut a piece (ideally top left corner) and include that second picture in the PDF report?
as example, a pheatmap code that produces a plot with 56 cols and 100's of rows. I would like to show only the left-top-most 10col and 10 rows but if I sample the input data, I obviously get another plot due to the clustering being done on different data. Also, I would love a solution applicable to any plot types (not only pheatmap).
drows <- "euclidean"
dcols <- "euclidean"
clustmet <- "complete"
col.pal <- c("lightgrey","blue")
main.title <- paste("Variant (freq>", minfreq, "%) in all samples", sep="")
hm.parameters.maj <- list(hm.maj.data,
color = col.pal,
fontsize = 10,
cellwidth = 14,
cellheight = 14,
scale = "none",
treeheight_row = 200,
kmeans_k = NA,
show_rownames = T,
show_colnames = T,
main = main.title,
clustering_method = clustmet,
cluster_rows = TRUE,
cluster_cols = FALSE,
clustering_distance_rows = drows,
clustering_distance_cols = dcols,
legend=FALSE)
# To draw the heatmap on screen (comment-out if you run the script from terminal)
do.call("pheatmap", hm.parameters.maj)
# To draw to file (you may want to adapt the info(header(vcf))sizes)
outfile <- paste("major-variants_heatmap_(freq>", minfreq, ")_", drows, ".pdf", sep="")
do.call("pheatmap", c(hm.parameters.maj, filename=outfile, width=24, height=35))
Thanks in advance
Stephane
I have the following R MWE making use of igraph (manual).
###################
##MWE
iref.sub <- matrix(c("2599030","2068280","9148596","2888723","5001159","2068280","2068280","2068280","2068280","1396470","855318","2068280","2068280","763487","855318","9148596","9148596","907507","907507","907507","2068280","2599030","763487","2068280","855318","4029829","2888723","907507","1375102","1646161","799094","955359","1110650","623716","1557992","1540685","917390","1215731","1025258|1119746","1609966","1625326","990926","X","X","X","X","X","X","X","X","X","X","C|X","X","X","X","1","1","1","1","1","1","1","1","1","1","1","1","1","1"), ncol=5)
mygraph <- convert_edgeList_to_graph(iref.sub, "undirected", "igraph")
#mylayout <- layout.kamada.kawai(simplify(mygraph, edge.attr.comb="min"))
mylayout <- layout.kamada.kawai(mygraph)
#postscript("test.eps", width = 6.83, height = 6, horizontal = FALSE, onefile = FALSE, paper = "special", colormodel = "cmyk", family = "Arial")
png(filename="test.png")
#plot(simplify(mygraph, edge.attr.comb="min"), layout=mylayout)
plot(mygraph, layout=mylayout)
dev.off()
###################
I use the option "simplify" to prevent loops from appearing, but such function doesn't seem to work... I get the following error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘simplify’ for signature ‘"igraph"’
In the MWE I show the line with the "simplify" option commented, notice how removing "simplify" the command works, but the loops that I want to avoid appear...
On another note, I don't want the output in .png format, but in .eps. I use the line:
postscript("test.eps", width = 6.83, height = 6, horizontal = FALSE, onefile = FALSE, paper = "special", colormodel = "cmyk", family = "Arial")
as specified in here and here. I use that line with no problem whatsoever when making all kinds of plots, but when using it with network like the one here, I get the error:
Error in text.default(x, y, labels = labels, col = label.color, family = label.family, :
family 'serif' not included in postscript() device
Please help!
Thanks to #bergant, I am posting here the answer.
-Use igraph::simplify in case there is another package masking the function.
-Add the option vertex.label.family="Arial" to override the serif default.
###################
##MWE
iref.sub <- matrix(c("2599030","2068280","9148596","2888723","5001159","2068280","2068280","2068280","2068280","1396470","855318","2068280","2068280","763487","855318","9148596","9148596","907507","907507","907507","2068280","2599030","763487","2068280","855318","4029829","2888723","907507","1375102","1646161","799094","955359","1110650","623716","1557992","1540685","917390","1215731","1025258|1119746","1609966","1625326","990926","X","X","X","X","X","X","X","X","X","X","C|X","X","X","X","1","1","1","1","1","1","1","1","1","1","1","1","1","1"), ncol=5)
mylayout <- layout.kamada.kawai(igraph::simplify(mygraph, edge.attr.comb="min"))
mylayout <- layout.kamada.kawai(mygraph)
postscript("test.eps", width = 6.83, height = 6, horizontal = FALSE, onefile = FALSE, paper = "special", colormodel = "cmyk", family = "Arial")
plot(igraph::simplify(mygraph, edge.attr.comb="min"), layout=mylayout, vertex.label.family="Arial")
dev.off()
###################