[R] boxplot notch

Chris Evans chr|@ho|d @end|ng |rom p@yctc@org
Fri Aug 16 18:20:28 CEST 2024


That's not really a reprex Sibylle.  I did try to use it to see if I 
could work out what you were trying to do and help but there is so much 
in there that I suspect is distraction from the notch issue and its 
error message.

Please can you give us something stripped of all unecessary things and 
tell us what you want?

Something like data that we can read as a tribble() or from a dput() of 
your data and then only the packages you actually need for the plot (I 
think tidyverse alone might do) and then a ggplot() call stripped right 
down to what you need and a clear explanation of what you are trying to 
do in the geom_boxplot() call and how it uses the summarised data tibble.

It may even be that if you do that, you will find what's causing the 
problem!  (I speak from bitter experience!!)

Very best (all),

Chris

On 16/08/2024 17:51, SIBYLLE STÖCKLI via R-help wrote:
> Farm_ID	Jahr	Bio	QI_A
> 1	2015	1	9.5
> 2	2018	1	15.7
> 3	2020	1	21.5
> 1	2015	1	50.5
> 2	2018	1	12.9
> 3	2020	1	11.2
> 1	2015	1	30.6
> 2	2018	1	28.7
> 3	2020	1	29.8
> 1	2015	1	30.1
> 2	2018	1	NA
> 3	2020	1	16.9
> 1	2015	0	6.5
> 2	2018	0	7.9
> 3	2020	0	10.2
> 1	2015	0	11.2
> 2	2018	0	18.5
> 3	2020	0	29.5
> 1	2015	0	25.1
> 2	2018	0	16.1
> 3	2020	0	15.9
> 1	2015	0	10.1
> 2	2018	0	8.4
> 3	2020	0	3.5
> 1	2015	0	NA
> 2	2018	0	NA
> 3	2020	0	3.5
>
>
> Code
> setwd("C:/Users/Sibylle Stöckli/Desktop/")
> #.libPaths()
> getwd()
>
> #libraries laden
> library("ggplot2")
> library("gridExtra")
> library(scales)
> library(nlme)
> library(arm)
> library(blmeco)
> library(stats)
> library(dplyr)
> library(ggpubr)
> library(patchwork)
> library(plotrix)
> library(tidyverse)
> library(dplyr)
>
> #read data
> MS = read.delim("Test1.txt", na.strings="NA")
> names(MS)
>
> MS$Jahr<-as.numeric(MS$Jahr)
> MS$Bio<-as.factor(MS$Bio)
> str(MS)
>
> ##### boxplot BFF QI
>
> MS1<- MS %>% filter(QI_A!="NA") %>% droplevels()
> MS1$Jahr<-as.factor(MS1$Jahr)
>
> MS1s <- MS1 %>%
>    group_by(MS1$Jahr, MS1$Bio) %>%
>    summarise(
>      y0 = quantile(QI_A, 0.05),
>      y25 = quantile(QI_A, 0.25),
>      y50 = mean(QI_A),
>      y75 = quantile(QI_A, 0.75),
>      y100 = quantile(QI_A, 0.95))
>
> MS1s
> colnames(MS1s)[1]<-"Jahr"
> colnames(MS1s)[2]<-"Bio"
> MS1s
>
> p1<-ggplot(MS1s, aes(Jahr,  fill = as.factor(Bio))) +
>    geom_boxplot(
>      aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100),
>      stat = "identity", notch=TRUE
>    ) +
>    theme(panel.background = element_blank())+
>    theme(axis.line = element_line(colour = "black"))+
>    theme(axis.text=element_text(size=18))+
>    theme(axis.title=element_text(size=20))+
>    ylab("Anteil BFF an LN [%]") +xlab("Jahr")+
>    scale_color_manual(values=c("red","darkgreen"), labels=c("ÖLN", "BIO"))+
>    scale_fill_manual(values=c("red","darkgreen"), labels= c("ÖLN", "BIO"))+
>    theme(legend.title = element_blank())+
>    theme(legend.text=element_text(size=20))
> p1<-p1 + expand_limits(y=c(0, 80))
> p1
-- 
Chris Evans (he/him)
Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, 
University of Roehampton, London, UK.
Work web site: https://www.psyctc.org/psyctc/
CORE site: http://www.coresystemtrust.org.uk/
Personal site: https://www.psyctc.org/pelerinage2016/
Emeetings (Thursdays): 
https://www.psyctc.org/psyctc/booking-meetings-with-me/
(Beware: French time, generally an hour ahead of UK)
<https://ombook.psyctc.org/book>
	[[alternative HTML version deleted]]



More information about the R-help mailing list