Dear Community,
any ideas why the scaling of these two plots behave that different and how to fix it? The scaling of p1
is quite fine in my opinion.
plotData <- structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L), .Label = c("Kompakt", "V1", "V1.2", "V2", "V3",
"V4.2", "V5", "V6", "V6.2", "V7", "V7.2"), class = "factor"),
mass = c(107.83, 107.87, 107.87, 107.88, 107.9, 107.64, 107.84,
107.86, 107.09, 107.85, 95.39, 95.47, 95.43, 95.47, 95.4,
95.35, 95.48, 95.43, 95.48, 95.5, 95.54, 95.5, 95.35, 95.33,
95.3, 95.34, 95.48, 95.43, 95.38, 94.21, 94.6, 94.56, 94.49,
94.54, 93.82, 94.57, 94.6, 94.8, 94.88, 94.69, 94.77, 94.5,
94.37, 94.56, 94.18, 94.9, 94.65, 94.75, 94.25, 94.48, 94.61,
94.51, 94.25, 94.67, 94.99, 95.13, 94.68, 94.71, 94.67, 94.54,
94.64, 95.12, 94.65, 94.11, 94.46, 94.37, 94.79, 95.37, 95.1,
94.48, 94.56, 94.62, 94.6, 94.42, 94.62, 94.61, 94.6, 94.52,
94.25, 94.49, 94.63, 94.51, 94.43, 94.48, 94.41, 94.46, 94.54,
91.79, 86.49, 90.29, 93, 94.06, 94.25, 94.15, 90.64, 88.53,
91.6, 92.81, 92.47, 92.32, 92.6, 92.08, 86.58, 91.77, 92.62,
93.17, 92.44, 89.73, 86.59, 87.53, 90.81, 92.13, 86.94, 83.84,
87.41, 91.03, 88.77, 87.37, 87.82, 88.01, 89.2, 88.39, 86.74,
87.65, 89.65, 89.24, 88.19, 89.17, 87.52, 88.9, 88.38, 89.37,
86.27, 90.92, 89.11, 89.44, 88.36, 86.6, 90.91, 88.8, 86.56,
89.18, 93.42, 93.86, 93.56, 91.17, 91.02, 93.31, 94.3, 94.76,
94.85, 94.21, 93.01, 92.07, 92.98, 93.91, 93.98, 93.67, 94.07,
93.77, 93.75, 93.99, 94.67, 94.52, 94.37, 94.44, 94.51, 94.65,
94.34, 94.3, 94.35, 94.39, 94.05, 94.62, 94.44, 94.36, 94.54,
94.37, 94.42), flaws = c(NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 1, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1, NA, NA, NA, NA, NA, 1, 1, NA, NA, 1, 1,
1, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, NA, NA, NA, NA, NA, NA, NA, 1,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -179L), groups = structure(list(
id = structure(1:11, .Label = c("Kompakt", "V1", "V1.2",
"V2", "V3", "V4.2", "V5", "V6", "V6.2", "V7", "V7.2"), class = "factor"),
.rows = list(1:10, 11L, 12:29, 30:49, 50:69, 70:87, 88:107,
108:124, 125:142, 143:162, 163:179)), row.names = c(NA,
-11L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))
p1 <- plotData %>%
plot_ly(
type = 'violin',
x = ~ id,
y = ~ mass,
split = ~ id,
box = list(visible = TRUE),
points = 'all',
pointpos = -1.8,
jitter = 0.3,
meanline = list(visible = TRUE)
) %>%
config(displayModeBar = F) %>%
layout(
xaxis = list(title = "Versuch"),
yaxis = list(title = "Masse", ticksuffix = ' g', showexponent = 'last'),
title = "Vergleich",
legend = list(
orientation = 'h',
xanchor = 'center',
x = 0.5,
y = -0.2
),
separators = ","
)
p1
pointposAll <- c(-.7, -.15, -.5, -.25, -.25, -.4, -.25, -.25, -.25, -.25, -.4)
pointposFlaws <- c(.7, .15, .5, .25, .25, .4, .25, .25, .25, .25, .4)
p2 <- plot_ly(type = 'violin')
for (i in 1:length(unique(plotData$id))) {
p2 <- add_trace(
p2,
x = ~ id,
y = ~ mass,
data = plotData %>% filter(id == unique(plotData$id)[i]),
hoveron = "points+kde",
legendgroup = 'Alle',
scalegroup = 'Alle',
name = 'Alle',
side = 'negative',
box = list(
visible = T
),
points = 'all',
pointpos = pointposAll[i],
jitter = 0,
scalemode = 'count',
fillcolor = "rgba(141, 211, 199, 0.5)",
meanline = list(
visible = T
),
line = list(
color = "#8dd3c7"
),
marker = list(
color = "#8dd3c7"
),
showlegend = ifelse(i == 1, TRUE, FALSE)
) %>%
add_trace(
x = ~ id,
y = ~ mass,
data = plotData %>% filter(id == unique(plotData$id)[i], is.na(flaws)),
hoveron = "points+kde",
legendgroup = 'Ohne Fehler',
scalegroup = 'Ohne Fehler',
name = 'Ohne Fehler',
side = 'positive',
fillcolor = "rgba(190, 186, 218, 0.5)",
box = list(
visible = T
),
points = 'all',
pointpos = pointposFlaws[i],
jitter = 0,
scalemode = 'count',
meanline = list(
visible = T
),
line = list(
color = "#bebada"
),
marker = list(
color = "#bebada"
),
showlegend = ifelse(i == 1, TRUE, FALSE)
)
}
p2 <- layout(
p2,
title = "Vergleich",
yaxis = list(
zeroline = F
),
violingap = 0,
violingroupgap = 0,
violinmode = 'overlay',
legend = list(
tracegroupgap = 0
),
xaxis = list(title = "Versuch"),
yaxis = list(title = "Masse", ticksuffix = ' g', showexponent = 'last')
)
p2
Additionally I get these warnings
"1: Can't display both discrete & non-discrete data on same axis"
"2: 'layout' objects don't have these attributes: 'violingap', 'violingroupgap', 'violinmode'"
My session info
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xEV_1.4.0 car_3.0-4 carData_3.0-2 plotly_4.9.1 R6_2.4.0 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3
[9] purrr_0.3.3 readr_1.3.1 tidyr_1.0.0 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 lubridate_1.7.4 lattice_0.20-38 assertthat_0.2.1 zeallot_0.1.0 digest_0.6.22 packrat_0.5.0
[8] utf8_1.1.4 mime_0.7 cellranger_1.1.0 backports_1.1.5 httr_1.4.1 pillar_1.4.2 rlang_0.4.1
[15] lazyeval_0.2.2 curl_4.2 readxl_1.3.1 rstudioapi_0.10 data.table_1.12.6 foreign_0.8-71 htmlwidgets_1.5.1
[22] munsell_0.5.0 shiny_1.4.0 broom_0.5.2 compiler_3.6.1 httpuv_1.5.2 modelr_0.1.5 pkgconfig_2.0.3
[29] htmltools_0.4.0 tidyselect_0.2.5 rio_0.5.16 XML_3.98-1.20 fansi_0.4.0 viridisLite_0.3.0 crayon_1.3.4
[36] withr_2.1.2 later_1.0.0 grid_3.6.1 nlme_3.1-140 jsonlite_1.6 xtable_1.8-4 gtable_0.3.0
[43] lifecycle_0.1.0 magrittr_1.5 scales_1.0.0 zip_2.0.4 cli_1.1.0 stringi_1.4.3 promises_1.1.0
[50] xml2_1.2.2 ellipsis_0.3.0 generics_0.0.2 vctrs_0.2.0 openxlsx_4.1.3 tools_3.6.1 glue_1.3.1
[57] hms_0.5.2 crosstalk_1.0.0 abind_1.4-5 fastmap_1.0.1 yaml_2.2.0 colorspace_1.4-1 rvest_0.3.4
[64] haven_2.2.0