Я копирую упрощенную версию пользовательской функции, с которой работаю. Функция работает нормально, но это warnings
, от которого я не смог избавиться. Эта функция будет частью пакета, и поэтому важно, чтобы пользователи не были сбиты с толку этими загадочными ошибками, и поэтому я хотел бы изменить сценарий таким образом, чтобы эти предупреждения больше не производились.
Предупреждение (см. полностью воспроизводимый пример ниже):
position_jitterdodge requires non-overlapping x intervals
Я уже проверил этот вопрос о position_jitterdodge
(предупреждение о позиции-уклонении с ggplot boxplot?) и это не очень помогло, так как на этом рисунке нет диаграммы.
Извиняюсь за затянутость вопроса и кода. Хотел предоставить все возможные детали, чтобы помочь диагностировать это.
# loading needed libraries
library(ggplot2)
library(dplyr)
library(devtools)
devtools::install_github("daattali/ggExtra")
library(ggExtra) # attach the development version
library(rlang)
# defining the custom function
ggscatterstats <-
function(data = NULL,
x,
y,
xfill = "orange",
yfill = "green",
marginal = NULL,
marginaltype = "histogram",
jitter.width = NULL,
jitter.height = 0.2,
dodge.width = 0.75) {
# preparing a dataframe out of provided inputs
if (!is.null(data)) {
# if dataframe is provided
data <-
dplyr::select(
.data = data,
x = !!rlang::enquo(x),
y = !!rlang::enquo(y)
)
} else {
# if vectors are provided
data <-
base::cbind.data.frame(x = x,
y = y)
}
# preparing the scatterplotplot
plot <-
ggplot2::ggplot(data = data,
mapping = aes(x = x,
y = y)) +
geom_count(
show.legend = FALSE,
colour = "black",
size = 3,
alpha = 0.5,
position = position_jitterdodge(
jitter.width = jitter.width,
jitter.height = jitter.height,
dodge.width = dodge.width
)
) +
geom_smooth(method = "lm",
se = TRUE,
size = 1.5) +
theme_grey()
# marginal plot will be shown by default
if (is.null(marginal))
marginal <- TRUE
if (isTRUE(marginal)) {
# creating the ggMarginal plot of a given marginaltype
plot <-
ggExtra::ggMarginal(
p = plot,
type = marginaltype,
size = 5,
xparams = list(fill = xfill,
col = "black"),
yparams = list(fill = yfill,
col = "black")
)
}
return(plot)
}
# using the function
ggscatterstats(data = iris, x = Sepal.Length, y = Petal.Width)
#> Warning: position_jitterdodge requires non-overlapping x intervals
#> Warning: position_jitterdodge requires non-overlapping x intervals
Создано 15 февраля 2018 г. с помощью пакета reprex (v0.1.1.9000).