size argument passed to annotations not respected?
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied add_annotations examples, including the font = list(size = ~size) form and the older layout approach. Trace the add_annotations entry point to see how annotation size is passed, then verify that annotations render with the requested per-row sizes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100