R plotly boxplots overwriting with numerical labels
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- R
- Sterne
- 2.7k
- Forks
- 641
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
R plotly boxplots overwriting with numerical labels
I've asked this question on SO here: https://stackoverflow.com/questions/76466189/r-plotly-boxplots-overwriting-with-numerical-labels, but I'm wondering if it's a bug with the latest versions of the plotly library in R
Plotting boxplots with numeric (or numeric-as-character) as x-variable results in boxplots a) not located in the correct locations and b) with boxes overplotted
library(plotly)
colors <- c("red","blue","green","pink","brown")
data.in <- data.frame(Age=25*rnorm(100)+50, IMD=sample(5,100,replace=TRUE))
fig <- plot_ly(data=data.in[data.in$IMD == "1",], y=~Age, type="box", color=I(colors[1]),name="1 - least")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "2",], y=~Age, type="box", color=I(colors[2]),name="2")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "3",], y=~Age, type="box", color=I(colors[3]),name="3")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "4",], y=~Age, type="box", color=I(colors[4]),name="4")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "5",], y=~Age, type="box", color=I(colors[5]),name="5 - most")
fig <- fig %>% layout(yaxis = list(title = "Age"),
xaxis = list(title = "IMD"),
boxgap = 0.1, boxgroupgap=0)
This results in a plot similar to
Specifying 'x=~' in each add_trace does place the boxes in the correct places so is a temporary workaround, but I think that this may be a bug with the package, as the above code with labels which don't start with numbers (in the 'name=' attribute) does give the correct placement:
library(plotly)
colors <- c("red","blue","green","pink","brown")
data.in <- data.frame(Age=25*rnorm(100)+50, IMD=sample(5,100,replace=TRUE))
fig <- plot_ly(data=data.in[data.in$IMD == "1",], y=~Age, type="box", color=I(colors[1]),name="A")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "2",], y=~Age, type="box", color=I(colors[2]),name="B")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "3",], y=~Age, type="box", color=I(colors[3]),name="C")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "4",], y=~Age, type="box", color=I(colors[4]),name="D")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "5",], y=~Age, type="box", color=I(colors[5]),name="E")
fig <- fig %>% layout(yaxis = list(title = "Age"),
xaxis = list(title = "IMD"),
boxgap = 0.1, boxgroupgap=0)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der bereitgestellten R-Reproduktion unter Verwendung von plot_ly(), add_trace() und layout(); vergleiche numerische und nichtnumerische Tracenamen sowie den expliziten x=-Workaround. Als erledigt gilt, dass Boxplot-Traces mit numerischen oder als Zeichen dargestellten numerischen Tracenamen unterschiedliche, beabsichtigte x-Positionen einnehmen, ohne explizite x-Werte zu erfordern. Im Issue wird keine Quelldatei und kein Test genannt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- plotly, r
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100