how to use ggplot2 make recursive partitioning survival tree - r

can everyone tell me how to use ggplot2 make recursive partitioning survival tree?
I know " party " package can make a plot in R, however the plot is not looking good, and all the plots in the rest of my report are made by ggplot2.
for my plot, I printsreen and added labels manually. if there is a way to input data and plot in R also works, Thanks!!

Related

How to convert S3 objects with class roc for ggplot2?

I'm planning to use patchwork to assemble several ROC curves plotted with pROC. After constructing a pROC plot list (of S3: roc objects) and attempting to use wrap_plots(plots) to assemble, I came across the following error:
Error: Only know how to add ggplots and/or grobs
AFAIK, there may be several solutions:
Coerce S3:roc objects to ggplots. It seems the function fortify does this job for S3 objects generated by precrec package but I don't know if S3:roc objects can be done in the same way. Using ggplot2::fortify I ran into
`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class roc.
Use precrec to streamline the conversion, instead. What curtails my migration is that I want to print Youden index point and confidence intervals of the Youden index point and area under curve (AUC) on the plot. It seems only pROC package meets all my needs so I don't quite want to move on. Also I need to adjust my codes to cater parameter demands from precrec. Too much to learn and try, so tutorials and simple codes are appreciated.
Whatever, my final purpose is being able to assemble all ROC curves programmatically, with automatic annotations. The ROC curves need to show their respective Youden index point and confidence intervals of the Youden index point and area under curve (AUC) on the plot.
Drawbacks exist in the pROC package, too. The text sizes of Youden index and confidence interval values are too small for the whole plot if all ROC plots are assembled. I can adjust them by specifying par(cex=<text size>) but there's ricks that the texts may overlap with the curves or get out of bound if the texts are too marginal. pROC is not smart enough to reconcile with text sizes, curves and text positions. A smarter package to meet all of my harsh demands mentioned above will strongly push me forward to adopt a new package to draw ROC curves. Therefore, solutions vary in my scenario (but please don't recommend using a graphical vector image editor to edit these curves by hand because it's time-consuming and error-prone, and lags changing demands from different journals). All insights from all perspectives are appreciated.
Have you tried the ggroc function from pROC? It does exactly what you're asking for: it creates a ggplot2 plot (class gg) which you can then manipulate as you wish.
However I think you are being slightly confused:
Coerce S3:roc objects to ggplots. It seems the function fortify does this job for S3 objects generated by precrec package
It makes sense that the precrec package would be able to convert its own objects. However, note that it doesn't generate a ggplot2 object, but a data.frame with the coordinates of the ROC curve (which can then be used as input for ggplot2).
In pROC, this exact operation is done with the coords function, which extracts the coordinates of the ROC curve to a data.frame (and that you can then use as input for ggplot2).

R GRMetric: How to personalize the plot design (themes, colors, legends, etc.)

I am relatively new to R and interested in Plotting Dose-Response curves. I have discovered GRMetrics which I found is very useful.
Example (as given in the documentary) will produce a scatter blot and plots the approximated function above them - perfect but how to persolanize the plot design with respect to the color of the points and curves, axis labels, thickness, etc.
In the documentaiton I found it is compatible with ggplot2 but I didn't found any example and didn't manage to integrate the output of GRMetric in a ggplot environment to edit the graph.
I appreciate any suggestion how to solve this issue.
The installation and code for GRMetrics:
if (!requireNamespace("BiocManager", quietly=TRUE))
install.packages("BiocManager")
BiocManager::install("GRmetrics")
install.packages("foreign")
browseVignettes("GRmetrics") #link to documentation
library(GRmetrics)
data(inputCaseA)
head(inputCaseA)
drc_output = GRfit(inputCaseA, groupingVariables =c('cell_line','agent'))
GRdrawDRC(drc_output)
In case someone is interested: one solution I found for this problem is....
1) export the curve parameters and data points from GRdrawDRC. The GRmetrics packages uses sigmoidal fitting and the function is given in its documentation
2) copy/insert the curve and all parameters in ggplot (e.g. as stat_function + geom_point()).
Then you are off to go and can format the graph easily.

R: getting data (instead of plot) back from sm.density.compare

I'm doing a density compare in R using the sm package (sm.density.compare). Is there anyway I can get a mathematical description of the graph or at least a table with number of points rather than a plot back? I would like to plot the resulting graphs in a different application, but need the data to do so.
Thanks a lot for the help,
culicidae

General questions about Principal Component Analysis (PCA) in R

I would like to produce some nice PCA plots in R. As usual, in R, there are several ways to perform a principal component analysis. I found so far 3 different ways of how to calculate your components and 3 ways of plotting them. I was wondering whether people who are familiar with these functions can give me some advise on the best combination of functions to produce the following plots:
Scores Plot
Loadings Plot
Histogram / Bar chart of the variances explained by each principal component
My research on functions and plots used for PCA in R resulted in:
Functions:
pca.xzy()
prcomp()
princomp()
dudi.pca()
Plot:
plot.pca (this one seems to belong to the function pca.xzy())
ggplot2
plot
biplot
I also found the following webpage:
http://pbil.univ-lyon1.fr/ade4/ade4-html/dudi.pca.html
And I was wondering if you can draw those circles and lines starting from each of the circle centers with one of the other functions mentioned above as the function dudi.pca from the ade4 package seems to be the most complicated one.
One question per question, please! There's psych package by William Revelle, see this and this. There's also a good tutorial here. Anyway...
for scores/loadings plot see pairs
histogram: see hist
So once again, what's your question actually? =)

Can I use shingles from lattice in ggplot2 in R

It is possible to use the shingles to define specific ranges in ggplot2. As far as i understand shingles are a way to generate groups. Can we create such shingles and use them in ggplot2 facet_grid to obtain graphs?
Following up from the comments, ggplot can't draw shingles (in the way lattice draws shingles with special indicators in the strip) and by default doesn't have a means of producing the overlapping groups.
However, I cam across this excellent PDF document which aims to produce a gpplot2 version of every figure in Depayan's excellent Lattice book (Lattice: Multivariate Data Visualization with R).
Page 31 contains a custom function fn() which replicates the behaviour of equal.count(), as far as I can tell, to provide the correct data structure to plot with overlapping shingles. The PDF contains plenty of examples of "shingles" in ggplot that you can play with.
So not sure if this answers the Q - but at least it appears one can fudge ggplot into producing plots that use the shingle concept.

Resources