Hello, for the bar plot I use the function:
library(rlang)
position_stack_repel <- function(vjust = 1, reverse = FALSE,
offset = 1) {
ggproto(NULL, PositionStackRepel, vjust = vjust, reverse = reverse,
offset = offset)
}
PositionStackRepel <- ggproto("PositionStackRepel", PositionStack,
type = NULL,
vjust = 1,
fill = FALSE,
reverse = FALSE,
offset = 1,
setup_params = function(self, data) {
list(
var = self$var %||% ggplot2:::stack_var(data),
fill = self$fill,
vjust = self$vjust,
reverse = self$reverse,
offset = self$offset
)
},
setup_data = function(self, data, params) {
data <- PositionStack$setup_data(data, params)
data <- data[order(data$x), ]
data$to_repel <- unlist(by(data, data$x, function(x) {
sapply(seq(nrow(x)), function(i) {
(x$y[i]) / sum(x$y) < 0.1 & (
(if (i != 1) (x$y[i-1] / sum(x$y)) < 0.1 else FALSE) | (
if (i != nrow(x)) (x$y[i+1] / sum(x$y)) < 0.1 else FALSE))
})
}))
data
},
compute_panel = function(data, params, scales) {
data <- PositionStack$compute_panel(data, params, scales)
data[data$to_repel, "x"] <- unlist(
by(data[data$to_repel, ], data[data$to_repel, ]$x,
function(x) seq(x$x[1] - 0.3, x$x[1] + 0.3, length.out = nrow(x))))
data
}
)![Unbenannt|426x229](upload://qRzC82DMTfG9dWkIiCQrk2uil5j.png)
My problem is, that the values are in the wrong position. Look at the picture, please.
The correct position is marked.
What can I make to correct the position? I know, that compute_panel isnĀ“t correct.
Thank you very much.