je réalise des boxplots en utilisant une fonction, un peu complexe à mon niveau, qu'un collègue avait écrite.
Autodidacte dans l'écriture de scripts, j'ai besoin de votre aide pour améliorer mes graphes.
Je souhaiterais améliorer ce qui se trouve dans les marges de gauche et haute.
Dans la marge haute, figure les valeurs des pvalues : je voudrais pouvoir augmenter la taille des caractères.
Dans la marge de gauche, 2 points :
a) je voudrais là aussi augmenter la taille des caractères du nom de l'axe y et/ou la taille des caractères des étiquettes.
b) parfois les valeurs des étiquettes comportent un nombre de chiffres plus important ce qui se traduit par une superposition de l'étiquette avec le nom de l'axe : comment définir la distance qui doit séparer les 2 ? Je n'y suis pas arrivée en augmentant la taille de la marge ..
Je vous remercie par avance de votre aide et vous souhaite une très agréable journée.
Patricia
voici le df pour une visualisation :
Code : Tout sélectionner
plate <- structure(list(Cond = c("KI", "KI", "KI", "KI", "KI", "KI", "KI",
"KI", "KI", "KI", "KI", "KI", "KI", "KI", "KI", "KI", "KI", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT",
"WT", "WT", "WT", "WT", "WT", "WT"), AreaNorm = c(113.105, 62.57625,
63.445, 122.689, 177.922, 384.605, 257.755555555556, 113.269285714286,
204.707, 250.348, 177.8625, 193.506666666667, 160.231111111111,
191.082, 253.38, 199.273333333333, 386.266666666667, 119.070833333333,
130.3185, 76.15375, 88.9104545454545, 82.639, 76.3433333333333,
74.6333333333333, 70.3033333333333, 46.4036363636364, 101.112307692308,
76.3807142857143, 98.58625, 165.852222222222, 124.689090909091,
222.500909090909, 107.690769230769, 105.618235294118, 120.751875,
99.9691304347826, 160.009411764706, 68.6766666666667, 206.824117647059,
167.765555555556, 61.6457142857143, 125.303529411765, 150.094666666667,
200.601764705882, 124.812666666667, 108.571666666667)), class = "data.frame", row.names = c(NA, -46L))
le script pour réaliser les boxplots :
Code : Tout sélectionner
x11()
op <- par(las=2, cex=0.8, oma=c(0,0,0,0))
quartilesignifboxplot(dataf=plate,int="AreaNorm",ag="Cond",cont="WT",
ylab="Area per Nuc in µm²",
shownumofobs=F,numpval=T,legendsize = 1,logval = FALSE,pos="topright",main="")
par(op)
le script pour la fonction :
Code : Tout sélectionner
quartilesignifboxplot <- function(dataf = plate,
int="Intensite.totale.du.DAB.dans.les.objets.segmentes",
ag = "gleasonsum", # controls column
control="-",
pos="topleft",
col="",
xlab="",
ylab="",
main="",
ylim="",
legendsize=1, # if = 0, no legend
shownumofobs=F,
numpval=F,
logval = FALSE,
hachure=NA)
{
if (length(control) != 1) {
print("Need one control")
stop
}
intens <- dataf[,int]
if (missing(main)) title <- paste(deparse(substitute(int)),"VS",deparse(substitute(ag)),sep=" ") else title <- main
if (missing(xlab)) xxlab <- "" else xxlab <- xlab
if (missing(ylab)) yylab <- "" else yylab <- ylab
if (logval) { # for log10 value expression
intens <- log10(intens)
dataf[,int] <- intens
title <- paste(title,"(log10)",sep=" ")
}
fac <- as.factor(dataf[,ag]) # the different factors
sel <- fac==control # only the control
meanint <- mean(dataf[sel,int],na.rm=TRUE)
fquart <- quantile(dataf[sel,int],0.25,na.rm=TRUE,type=7) # type = 7 because its the mode that looks boxplot quartile the most
tquart <- quantile(dataf[sel,int],0.75,na.rm=TRUE,type=7)
medianint <- median(dataf[sel,int],na.rm=TRUE)
num_fac <- length(levels(fac))
if (missing(col)) { # if the colors is not specified, they are automatically build with rainbow
if (missing(ylim)) # if there was no ylim specified, the classical plot is built
{bp <- boxplot(dataf[,int]~dataf[,ag],col=rainbow(num_fac),main=title,xlab=xxlab,ylab=yylab)}
else # else we consider the user defined ylim
{bp <- boxplot(dataf[,int]~dataf[,ag],col=rainbow(num_fac),main=title,xlab=xxlab,ylab=yylab,ylim=ylim)}
}
else { # else the colors are user specified
if (missing(ylim)) bp <- boxplot(dataf[,int]~dataf[,ag],col=col,main=title,xlab=xxlab,ylab=yylab)
else bp <- boxplot(dataf[,int]~dataf[,ag],col=col,main=title,xlab=xxlab,ylab=yylab,ylim=ylim)
}
if (! is.na(hachure)) {
rect(hachure-0.4,bp$stats[2,hachure],hachure+0.4,bp$stats[4,hachure],border=NA, density=12, angle=45)
}
# plot the mean, median, quartile lines
abline(h=meanint,col="red",lwd=2)
abline(h=fquart,col="orange",lwd=2)
abline(h=tquart,col="orange",lwd=2)
abline(h=medianint,col="blue",lwd=2)
grid()
if (legendsize != 0) legend(pos,legend=c("moyenne","medianne","1er quartile","3eme quartile"),lty=1,col=c("red","blue","orange","orange"),cex=legendsize,lwd=2)
i <- 0
for (fa in levels(fac)){
i <- i + 1
numofobs <- length(dataf[ fac == fa,int])
if (fa == control) {
mtext("ctl",3,at=i)
if (shownumofobs) mtext(numofobs,1,at=i,line=2) # show the number of observation if shownumofobs is True
}
else {
pval <- signif(wilcox.test(dataf[sel,int],dataf[ fac == fa,int])$p.value,3)
if (numpval) {
mtext(pval,3,at=i,cex=0.5)
}
else {
if (pval <= 0.001) {mtext("***",3,at=i)}
else if (pval <= 0.01) {mtext("**",3,at=i)}
else if (pval <= 0.05) {mtext("*",3,at=i)}
else {mtext("-",3,at=i)}
}
}
if (shownumofobs) mtext(numofobs,1,at=i,line=2)
}
}