With Head in the Clouds
Statistics with R and other stuff: tips&doubts
Wednesday, 1 March 2023
FINDING A MISSED FILE IN THE PC BY THE SHELL
Saturday, 19 November 2022
VOLCANO PLOTS CUSTOMIZATION IN R
Volcano plots became famous with big data analysis. Whether you are working with NGS, mass spectrometry data or similar, you might need to build this kind of plot.
logFC: it contains the logarithm base 2 (log2) of the fold change of each gene
PValue: it contains p-values for each comparison
FDR:
false discovery rate
We will use the FDR column, whose values need to be converted to their negative logarithm base 10 [log10(FDR)]. We’ll do it later, in the ‘ggplot()’ function.
DIFFERENTIALLY EXPRESSED GENES (DEGs)
Therefore, we’ll add the variable “Expression” where classifying the genes as up-/down-regulated or unchanged according to the FDR and fold change:
Now, it is possible to count how many genes are up-/down-regulated or unchanged:
BUILDING THE BASIC VOLCANO PLOT
ADDING THE LINES FOR SIGNIFICANCE
x <- log(2, 2) #this is for the fold change, the log base 2 of 2
p2 <- p1 +
SELECTED GENES
The
‘geom_label_repel()’ function, will move slightly the labels to avoid their
overlapping. You can change the colour, size and shape of the highlighted points
with the specific arguments in ’geom_point()’.
TOP GENES
To highlight the top genes we can use the ordered up-regulated and down-regulated genes we previously saved in the objects “up” and “down”.
We’ll select only the top 10 genes for up-regulated and down-regulated ones, and put them together in a data frame:
Now we can use this data frame similarly to the previous example:
SINGLE GENE
Sunday, 11 April 2021
BUILDING DOT PLOTS IN R SIMILAR TO THOSE WITH GraphPad
Have you ever had the necessity to build a dot plot in R that looks like the nice ones obtained with GraphPad?
Tuesday, 17 July 2018
GETTING THE AUTHORISATION TO MODIFY A FOLDER/FILE (changing permissions)
Are you trying to modify a file/folder but you have not the authorisation? Did you get back a message like the following?
"You are not allowed to open the file. Ask the owner or the admin for getting the authorisation" |
Try to follow this step-by-step easy guide:
1. Click right on the folder/file
2. Select Properties from the Context Menu
3. In the Security tab click on the "Edit" button
4. In the first box Users and Groups select "Users" and in the second box Authorisation for Users check "Allow" on "Complete Control"
5. Finally click on Apply button and you will be able to modify your folder/file.
For additional methods, you can have a look at this link.
If you have a better technique, please let me know!
Monday, 18 December 2017
LITTLE TROUBLESHOOTING IN R
Using R, little troubles can arise. Below, a "work in progress" collection of solved problems...or not yet...
- ERRONEOUSLY SAVED WORKSPACE
If you want to delete the workspace you saved, check into the Documents folder and delete both files that appear as "R Workspace" and "Rhistory". That's all!!
- FISHER'S EXACT TEST ERROR MESSAGES: "FEXACT error 6 and 7"
Have you ever got error messages performing Fisher's exact test? Well, I have got two different error messages that I solved with the same "tricks":
LDKEY is too small for this problem.
Try increasing the size of the workspace.
fisher.test(data,workspace=2e8) #change data with the name of your table
If it still doesn't work, you can go for a simulation:
fisher.test(data,simulate.p.value=TRUE,B=1e7)
where simulate.p.value is a logical for computing p-value by Monte Carlo simulation and B indicates the number of replicates (by default B=2000), that can be changed as needed.
I know, it is not exactly the same...but at least you can run the analysis.
As usual, if you have a better solution, please let me know!
- NEW VERSION NOT WRITABLE: " '/R-X.X.X/library' is not writable"
Have you just updated the R version but can't update the library because the folder is not writable?
Don't worry! You have two different options:
1. the easiest way is to create a private library. Just say "Yes" when R will ask you (and take note of the location of the folder);
2. if you still want to write in the library folder, you can get the authorisation following the easy instructions I provided in this post.
- ANOVA ERROR MESSAGES: "Error in eigen" OR "Error in contrasts"
If you perform a mixed ANOVA, either using aov() or anova_test() (from rstatix package), you could run into these error messages: