I am using the following example to test my data in pca.
I was hoping to extract the data points used to plot PCA scatter chart with ggbiplot function. I couldnt find anything in ggbiplot documentation, but maybe someone is aware of an alternative ?
Thank you
The ir.pca object has several properties, and one of them is "x", which had all the points I was looking for.
This was what led me to an answer.
Related
I have a fair amount of experience analyzing RNA-Seq data, but I am looking for new ways to visualize the data. I typically use heat maps and volcano plots, but I'd like to make this plot which is from this paper. I can make this type of plot with rlog transformed data before doing DEG analysis, but I want to color dots based on statistically significant expression differences.
I've search online and have not been able to find a good way to create this plot. Thanks in advance for any advice.
This question is more about bioinformatics so maybe it is better you can post it on biostar.
In any case, maybe you can draw a scatter plot with the package "ggscatter" or "ggplot2" and colour the statistically significant gene with an if else statement.
Please, provide sample of your data.
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.
I have a plotting problem with curves when using mixtools
Using the following R code
require(mixtools)
x <- c(rnorm(10000,8,2),rnorm(10000,18,5))
xMix <- normalmixEM(x, lambda=NULL, mu=NULL, sigma=NULL)
plot(xMix, which = 2, nclass=25)
I get a nice histogram, with the 2 normal curves estimated from the model superimposed.
The problem is with the default colours (i.e. red and green), which I need to change for a publication to be black and grey.
One way I thought to doing this was first to produce the histogram
hist(xMix$x, freq=FALSE, nclass=25)
and then add the lines using the "curve" function.
....... but I lost my way, and couldn't solve it
I would be grateful for any pointers or the actual solution
thanks
PS. Note that there is an alternative work-around to this problem using ggplot:
Any suggestions for how I can plot mixEM type data using ggplot2
but for various reasons I need to keep using the base graphics
You can also edit the colours directly using the col2 argument in the mixtools plotting function
For example
plot(xMix, which = 2, nclass=25, col2=c("dimgrey","black"))
giving the problem a bit more thought, I managed to rephrase the problem and ask the question in a much more direct way
Using user-defined functions within "curve" function in R graphics
this delivered two nice solutions of how to use the "curve" function to draw normal distributions produced by the mixture modelling.
the overall answer therefore is to use the "hist" function to draw a histogram of the raw data, then the "curve" function (incorporating the sdnorm function) to draw each normal distribution. This gives total control of the colours (and potentially any other graphic parameter).
And not to forget - this is where I got the code for the sdnorm function - and other useful insights
Any suggestions for how I can plot mixEM type data using ggplot2
Thanks as always to StackOverflow and the contributors who provide such helpful advice.
Does anyone know how to draw multiple 3d plots in one picture using RGL in R Statistics.
I have three variables and each of those variables belong to two groups. I want each group to have a different color so I can visualize it. In regular R stats, I just use subset and then use par(new=T). I haven't seen anything equivalent for the 3d plot. Does anyone have any suggestion?
Thanks!
try plot3d(x, y, z, add=TRUE)
Admittedly I was a bit surprised when it worked, I thought it would throw an error on the first plot, but i guess it creates an existing plot if none exists and otherwise adds the points to the existing plot
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? =)