[R] geom_boxplot nocht=TRUE
sibyiie@stoeckii m@iii@g oii gmx@ch
sibyiie@stoeckii m@iii@g oii gmx@ch
Thu Aug 15 11:50:53 CEST 2024
Dear community
I tried to run my ggplot() +geom_boxplot() code using nocht=TRUE, but probably my term noch=TRUE is at the wrong position?
Error:
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
> rlang::last_trace()
<error/rlang_error>
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
---
Backtrace:
▆
1. ├─base (local) `<fn>`(x)
2. └─ggplot2:::print.ggplot(x)
3. ├─ggplot2::ggplot_gtable(data)
4. └─ggplot2:::ggplot_gtable.ggplot_built(data)
5. └─ggplot2:::by_layer(...)
6. ├─rlang::try_fetch(...)
7. │ ├─base::tryCatch(...)
8. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
9. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
10. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
11. │ └─base::withCallingHandlers(...)
12. └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
13. └─l$draw_geom(d, layout)
14. └─ggplot2 (local) draw_geom(..., self = self)
15. └─self$geom$draw_layer(...)
16. └─ggplot2 (local) draw_layer(..., self = self)
17. └─base::lapply(...)
18. └─ggplot2 (local) FUN(X[[i]], ...)
19. ├─rlang::inject(self$draw_panel(data, panel_params, coord, !!!params))
20. └─self$draw_panel(...)
21. └─ggplot2 (local) draw_panel(..., self = self)
22. └─base::lapply(...)
23. └─ggplot2 (local) FUN(X[[i]], ...)
24. └─self$draw_group(group, panel_params, coord, ...)
25. └─ggplot2 (local) draw_group(..., self = self)
26. ├─ggplot2:::data_frame0(...)
27. │ └─vctrs::data_frame(..., .name_repair = "minimal")
28. │ └─rlang::list2(...)
29. └─base::ifelse(notch, data$notchlower, NA)
Run rlang::last_trace(drop = FALSE) to see 5 hidden frames.
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]]
More information about the R-help
mailing list