Re: [R] allequal diff

2024-08-16 Thread Ivan Krylov via R-help
В Fri, 16 Aug 2024 07:19:38 +0200
SIBYLLE STÖCKLI via R-help  пишет:

> Is it possible to consider na.rm=TRUE?

> > all.equal(getValues(r1), getValues(r2_resampled), tolerance = 0)  
> 
> [1] "'is.NA' value mismatch: 9544032 in current 66532795 in target"

Use is.na() on getValues() outputs, combine the two masks using the |
operator to get a mask of values that are missing in either raster,
then negate the mask to choose the non-missing values:

all.equal(getValues(r1)[!mask], getValues(r2)[!mask])

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] allequal diff

2024-08-16 Thread SIBYLLE STÖCKLI via R-help
Many thanks Ivan


Use is.na() on getValues() outputs, combine the two masks using the | operator 
to get a mask of values that are missing in either raster, then negate the mask 
to choose the non-missing values:

all.equal(getValues(r1)[!mask], getValues(r2)[!mask])

--> what do you mean by use is.na() in getValues(). So I need to call getValues 
a second time? I suppose you mean to first prepare a mask using is.na without 
getValues and then in the second step your code?

Kind regards
Sibylle

-Original Message-
From: Ivan Krylov  
Sent: Friday, August 16, 2024 9:28 AM
To: SIBYLLE STÖCKLI via R-help 
Cc: sibylle.stoec...@gmx.ch
Subject: Re: [R] allequal diff

В Fri, 16 Aug 2024 07:19:38 +0200
SIBYLLE STÖCKLI via R-help  пишет:

> Is it possible to consider na.rm=TRUE?

> > all.equal(getValues(r1), getValues(r2_resampled), tolerance = 0)
> 
> [1] "'is.NA' value mismatch: 9544032 in current 66532795 in target"

Use is.na() on getValues() outputs, combine the two masks using the | operator 
to get a mask of values that are missing in either raster, then negate the mask 
to choose the non-missing values:

all.equal(getValues(r1)[!mask], getValues(r2)[!mask])

--
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] allequal diff

2024-08-16 Thread Ivan Krylov via R-help
В Fri, 16 Aug 2024 10:35:35 +0200
 пишет:

> what do you mean by use is.na() in getValues(). So I need to call
> getValues a second time?

Not necessarily, but it's one of the options. I was thinking along the
lines of:

values1 <- getValues(r1)
mask1 <- is.na(values1)
# Do the same for r2
# Combine the masks
all.equal(values1[!combined_mask], values2[!combined_mask])

Unlike compareRaster(), this assumes that the coordinate grid of r1 and
r2 is already the same and that only some of the values may differ.

> I suppose you mean to first prepare a mask using is.na without
> getValues and then in the second step your code?  

'raster' documentation says that is.na() works on raster objects, so it
should work.

Even if it didn't work, since you already access the underlying data
using getValues() and then compare the resulting vectors using
all.equal(), using is.na(getValues(...)) should definitely work.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] allequal diff

2024-08-16 Thread SIBYLLE STÖCKLI via R-help
Here my idea including the error:

 

> m1=r1[r1="NA",]

> m2=r2_resampled[r2_resampled="NA",]

> 

> 

> all.equal(getValues(r1)[!m1], getValues(r2_resampled)[!m2])

[1] "Numeric: lengths (80706867, 65806339) differ"

 

-Original Message-
From: R-help  On Behalf Of SIBYLLE STÖCKLI via 
R-help
Sent: Friday, August 16, 2024 10:36 AM
To: 'Ivan Krylov' ; 'SIBYLLE STÖCKLI via R-help' 

Subject: Re: [R] allequal diff

 

Many thanks Ivan

 

 

Use is.na() on getValues() outputs, combine the two masks using the | operator 
to get a mask of values that are missing in either raster, then negate the mask 
to choose the non-missing values:

 

all.equal(getValues(r1)[!mask], getValues(r2)[!mask])

 

--> what do you mean by use is.na() in getValues(). So I need to call getValues 
a second time? I suppose you mean to first prepare a mask using is.na without 
getValues and then in the second step your code?

 

Kind regards

Sibylle

 

-Original Message-

From: Ivan Krylov <  ikry...@disroot.org>

Sent: Friday, August 16, 2024 9:28 AM

To: SIBYLLE STÖCKLI via R-help <  
r-help@r-project.org>

Cc:   sibylle.stoec...@gmx.ch

Subject: Re: [R] allequal diff

 

В Fri, 16 Aug 2024 07:19:38 +0200

SIBYLLE STÖCKLI via R-help <  
r-help@r-project.org> пишет:

 

> Is it possible to consider na.rm=TRUE?

 

> > all.equal(getValues(r1), getValues(r2_resampled), tolerance = 0)

> 

> [1] "'is.NA' value mismatch: 9544032 in current 66532795 in target"

 

Use is.na() on getValues() outputs, combine the two masks using the | operator 
to get a mask of values that are missing in either raster, then negate the mask 
to choose the non-missing values:

 

all.equal(getValues(r1)[!mask], getValues(r2)[!mask])

 

--

Best regards,

Ivan

 

__

  R-help@r-project.org mailing list -- To 
UNSUBSCRIBE and more, see   
https://stat.ethz.ch/mailman/listinfo/r-help

PLEASE do read the posting guide   
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] allequal diff

2024-08-16 Thread SIBYLLE STÖCKLI via R-help
Cool thanks

# values and mask r1
r1 <- getValues(r1)
mask1 <- is.na(r1)
# Do the same for r2
r2 <- getValues(r2_resampled)
mask2 <- is.na(r2)

# Combine the masks
all.equal(r1[!(mask1 & mask2)], r2[!(mask1 & mask2)])


output
> all.equal(r1[!(mask1 & mask2)], r2[!(mask1 & mask2)])
[1] "'is.NA' value mismatch: 389 in current 56989152 in target"

--> so there is just a mismatch in NA not in the xy pixels, right?

Sibylle 



-Original Message-
From: Ivan Krylov  
Sent: Friday, August 16, 2024 10:51 AM
To: sibylle.stoec...@gmx.ch
Cc: 'SIBYLLE STÖCKLI via R-help' 
Subject: Re: [R] allequal diff

В Fri, 16 Aug 2024 10:35:35 +0200
 пишет:

> what do you mean by use is.na() in getValues(). So I need to call 
> getValues a second time?

Not necessarily, but it's one of the options. I was thinking along the lines of:

values1 <- getValues(r1)
mask1 <- is.na(values1)
# Do the same for r2
# Combine the masks
all.equal(values1[!combined_mask], values2[!combined_mask])

Unlike compareRaster(), this assumes that the coordinate grid of r1 and
r2 is already the same and that only some of the values may differ.

> I suppose you mean to first prepare a mask using is.na without 
> getValues and then in the second step your code?

'raster' documentation says that is.na() works on raster objects, so it should 
work.

Even if it didn't work, since you already access the underlying data using 
getValues() and then compare the resulting vectors using all.equal(), using 
is.na(getValues(...)) should definitely work.

--
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] allequal diff

2024-08-16 Thread Ivan Krylov via R-help
В Fri, 16 Aug 2024 11:32:58 +0200
 пишет:

> # values and mask r1
> r1 <- getValues(r1)
> mask1 <- is.na(r1)
> # Do the same for r2
> r2 <- getValues(r2_resampled)
> mask2 <- is.na(r2)
> 
> # Combine the masks
> all.equal(r1[!(mask1 & mask2)], r2[!(mask1 & mask2)])

Let's consider a more tangible example:

# The vectors `x` and `y` start out equal
x <- y <- 1:10
# But then their different elements are made missing
x[c(1,3,4)] <- NA
y[c(3,8)] <- NA

Now, `is.na(x) & is.na(y)` gives the third element as the only element
missing in both x and y:

mask1 <- is.na(x)
mask2 <- is.na(y)
all.equal( # not the comparison you are looking for
 x[!(mask1 & mask2)], # still two more elements missing
 y[!(mask1 & mask2)]  # still one more element missing
)

If you want to ignore all missing elements, you should combine the
masks using the element-wise "or" operation ("missing in x and/or y"),
not the element-wise "and" operation ("missing in both x and y at the
same time"):

mask1 & mask2 # drops element 3
# [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
mask1 | mask2 # drops elements 1, 3, 4, 8
# [1]  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Is there some place where I can check a changelog / NEWS for the grid package?

2024-08-16 Thread Iago Giné Vázquez
Hi all,

On one hand, I wanted to ask if there is some place where I can check a 
changelog / NEWS for the grid package, as it is not on CRAN. And in that case, 
where can I find it?

On the other hand, I wanted to ask you for tutorials to start understanding the 
grid package or what other recommendations you have of introductions to that 
package (and their extensions...)

Best regards,

Iago








[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there some place where I can check a changelog / NEWS for the grid package?

2024-08-16 Thread Uwe Ligges


On 16.08.2024 13:46, Iago Giné Vázquez wrote:

Hi all,

On one hand, I wanted to ask if there is some place where I can check a 
changelog / NEWS for the grid package, as it is not on CRAN. And in that case, 
where can I find it?


Grid is part of R, hence you can look at R's NEWS, e.g. at



or directly in the svn commit messages at the svn server

svn.r-project.org/R/trunk/






On the other hand, I wanted to ask you for tutorials to start understanding the 
grid package or what other recommendations you have of introductions to that 
package (and their extensions...)


Paul MUrrell wrote some papers and a book, but there are also the 
vignettes, type


vignette(package="grid")


to get an overview.


Best,
Uwe Ligges



Best regards,

Iago








[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] boxplot notch

2024-08-16 Thread SIBYLLE STÖCKLI via R-help
Dear community

 

I tried the following code using geom_boxplot() and notch=TRUE. Does anyone
know if the command �notch=TRUE� is at the wrong place in my special code
construct?

 

Without notch=TRUE the code provides the planned ggplot.

 

Kind regards

Sibylle

 

Code:

 

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


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] boxplot notch

2024-08-16 Thread Ben Bolker
  I don't see anything obviously wrong here. There may be something 
subtle, but we probably won't be able to help without a reproducible 
example ...


On 2024-08-16 9:24 a.m., SIBYLLE STÖCKLI via R-help wrote:

Dear community

  


I tried the following code using geom_boxplot() and notch=TRUE. Does anyone
know if the command �notch=TRUE� is at the wrong place in my special code
construct?

  


Without notch=TRUE the code provides the planned ggplot.

  


Kind regards

Sibylle

  


Code:

  


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


[[alternative HTML version deleted]]


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
> E-mail is sent at my convenience; I don't expect replies outside of 
working hours.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] boxplot notch

2024-08-16 Thread SIBYLLE STÖCKLI via R-help
Thanks Ben,

Here the reproducible example.
It works without notch=TRUE, but provides an error with notch=TURE

Error in `geom_boxplot()`:
! Problem while converting geom to grob.
ℹ Error occurred in the 1st layer.
Caused by error in `ans[ypos] <- rep(yes, length.out = len)[ypos]`:
! replacement has length zero
Run `rlang::last_trace()` to see where the error occurred.
Warning message:
In rep(yes, length.out = len) : 'x' is NULL so the result will be NULL


Data
Farm_ID JahrBio QI_A
1   20151   9.5
2   20181   15.7
3   20201   21.5
1   20151   50.5
2   20181   12.9
3   20201   11.2
1   20151   30.6
2   20181   28.7
3   20201   29.8
1   20151   30.1
2   20181   NA
3   20201   16.9
1   20150   6.5
2   20180   7.9
3   20200   10.2
1   20150   11.2
2   20180   18.5
3   20200   29.5
1   20150   25.1
2   20180   16.1
3   20200   15.9
1   20150   10.1
2   20180   8.4
3   20200   3.5
1   20150   NA
2   20180   NA
3   20200   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

-Original Message-
From: R-help  On Behalf Of Ben Bolker
Sent: Friday, August 16, 2024 3:30 PM
To: r-help@r-project.org
Subject: Re: [R] boxplot notch

   I don't see anything obviously wrong here. There may be something subtle, 
but we probably won't be able to help without a reproducible example ...

On 2024-08-16 9:24 a.m., SIBYLLE STÖCKLI via R-help wrote:
> Dear community
> 
>   
> 
> I tried the following code using geom_boxplot() and notch=TRUE. Does 
> anyone know if the command  notch=TRUE  is at the wrong place in my 
> special code construct?
> 
>   
> 
> Without notch=TRUE the code provides the planned ggplot.
> 
>   
> 
> Kind regards
> 
> Sibylle
> 
>   
> 
> Code:
> 
>   
> 
> 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
> 
> 
>   [[alternative HTML version deleted]]
> 
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.o

Re: [R] boxplot notch

2024-08-16 Thread Bert Gunter
Probably should be:
rep("yes", length.out = len)[ypos]

as yes is probably a nonexistent variable.

But I didn't examine your code in detail, so just ignore if I'm wrong.

-- Bert

On Fri, Aug 16, 2024 at 8:51 AM SIBYLLE STÖCKLI via R-help
 wrote:
>
> Thanks Ben,
>
> Here the reproducible example.
> It works without notch=TRUE, but provides an error with notch=TURE
>
> Error in `geom_boxplot()`:
> ! Problem while converting geom to grob.
> ℹ Error occurred in the 1st layer.
> Caused by error in `ans[ypos] <- rep(yes, length.out = len)[ypos]`:
> ! replacement has length zero
> Run `rlang::last_trace()` to see where the error occurred.
> Warning message:
> In rep(yes, length.out = len) : 'x' is NULL so the result will be NULL
>
>
> Data
> Farm_ID JahrBio QI_A
> 1   20151   9.5
> 2   20181   15.7
> 3   20201   21.5
> 1   20151   50.5
> 2   20181   12.9
> 3   20201   11.2
> 1   20151   30.6
> 2   20181   28.7
> 3   20201   29.8
> 1   20151   30.1
> 2   20181   NA
> 3   20201   16.9
> 1   20150   6.5
> 2   20180   7.9
> 3   20200   10.2
> 1   20150   11.2
> 2   20180   18.5
> 3   20200   29.5
> 1   20150   25.1
> 2   20180   16.1
> 3   20200   15.9
> 1   20150   10.1
> 2   20180   8.4
> 3   20200   3.5
> 1   20150   NA
> 2   20180   NA
> 3   20200   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
>
> -Original Message-
> From: R-help  On Behalf Of Ben Bolker
> Sent: Friday, August 16, 2024 3:30 PM
> To: r-help@r-project.org
> Subject: Re: [R] boxplot notch
>
>I don't see anything obviously wrong here. There may be something subtle, 
> but we probably won't be able to help without a reproducible example ...
>
> On 2024-08-16 9:24 a.m., SIBYLLE STÖCKLI via R-help wrote:
> > Dear community
> >
> >
> >
> > I tried the following code using geom_boxplot() and notch=TRUE. Does
> > anyone know if the command  notch=TRUE  is at the wrong place in my
> > special code construct?
> >
> >
> >
> > Without notch=TRUE the code provides the planned ggplot.
> >
> >
> >
> > Kind regards
> >
> > Sibylle
> >
> >
> >
> > Code:
> >
> >
> >
> > 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(value

Re: [R] boxplot notch

2024-08-16 Thread Chris Evans via R-help
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   JahrBio QI_A
> 1 20151   9.5
> 2 20181   15.7
> 3 20201   21.5
> 1 20151   50.5
> 2 20181   12.9
> 3 20201   11.2
> 1 20151   30.6
> 2 20181   28.7
> 3 20201   29.8
> 1 20151   30.1
> 2 20181   NA
> 3 20201   16.9
> 1 20150   6.5
> 2 20180   7.9
> 3 20200   10.2
> 1 20150   11.2
> 2 20180   18.5
> 3 20200   29.5
> 1 20150   25.1
> 2 20180   16.1
> 3 20200   15.9
> 1 20150   10.1
> 2 20180   8.4
> 3 20200   3.5
> 1 20150   NA
> 2 20180   NA
> 3 20200   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)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] boxplot notch

2024-08-16 Thread CALUM POLWART
Unless I'm missing the point, you are sending the summary data MS1s to the
plot.  Is that not a VERY unusual way to do it. Let box plot do the
summary? Otherwise what do you want the notches to show?

On Fri, 16 Aug 2024, 17:21 Chris Evans via R-help, 
wrote:

> 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   JahrBio QI_A
> > 1 20151   9.5
> > 2 20181   15.7
> > 3 20201   21.5
> > 1 20151   50.5
> > 2 20181   12.9
> > 3 20201   11.2
> > 1 20151   30.6
> > 2 20181   28.7
> > 3 20201   29.8
> > 1 20151   30.1
> > 2 20181   NA
> > 3 20201   16.9
> > 1 20150   6.5
> > 2 20180   7.9
> > 3 20200   10.2
> > 1 20150   11.2
> > 2 20180   18.5
> > 3 20200   29.5
> > 1 20150   25.1
> > 2 20180   16.1
> > 3 20200   15.9
> > 1 20150   10.1
> > 2 20180   8.4
> > 3 20200   3.5
> > 1 20150   NA
> > 2 20180   NA
> > 3 20200   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)
> 
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.