plotly / plotly/plotly.R

size argument passed to annotations not respected?

Offen
#745 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug enhancement
Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I understand this issue has a chance of being an off-topic implementation issue. If so, please accept my sincere apologies in advance. Frank Harrell reported he is unable to change size of the annotated text using the code below.

require(plotly)
p <- plot_ly()
p <- add_markers(p,x=~1:2, y=~1:2)
p <- add_annotations(p, x=~c(1.1, 2.1), y=~c(1.2, 2.4),
                     text=~c('XXX','YYY'), size=~c(7,20))
p

I was unable to account for size of text using the 'old' method using 'layout' (as discussed in #744).

ann <- data.frame(x = c(1.1, 2.1),
                  y = c(1.2, 2.4),
                  size = c(10, 20),
                  text = c("XXX", "YYY"))
xy <- data.frame(x = c(1, 2), y = c(1, 2))

a <- vector("list", nrow(ann))

for (i in 1:nrow(ann)) {
  a[[i]] <- list(
    x = ann$x[i],
    y = ann$y[i],
    text = ann$text[i],
    xref = "x", yref = "y",
    showarrow = TRUE,
    size = ann$size[i]
  )
}

plot_ly(xy, x = ~x, y = ~y) %>%
  add_markers() %>%
  layout(annotations = a)

@cpsievert suggested using add_annotations but I'm a bit lost on how to pass on the size argument. Based on the documentation and some examples scattered over the internet, I tried

plot_ly(xy, x = ~x, y = ~y) %>%
  add_markers() %>%
  add_annotations(text = ~text, font = list(size = ~size), data = ann)

with no luck. Is there something I'm doing wrong?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die bereitgestellten add_annotations-Beispiele zu reproduzieren, einschließlich der Form font = list(size = ~size) und des älteren Layout-Ansatzes. Verfolge den Einstiegspunkt add_annotations, um zu sehen, wie die Größe der Annotation übergeben wird, und überprüfe anschließend, dass Annotationen mit den angeforderten Größen pro Zeile gerendert werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
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
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.