bug with the font parameter for annotation
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- R
- Star
- 2.7k
- Fork
- 641
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I want to add an annotation to a plotly heatmap. There is a bug with the font parameter. I've followed the example given here.
library(plotly)
### heatmap data ###
x <- 1:3; y <- 3:5
dd <- transform(expand.grid(x=x, y=y), z=x+y)
### plotly graphic ###
pp <- plot_ly(data=dd, x=~x, y=~y, z=~z, type="heatmap",
hoverinfo = 'text',
text = ~paste('<em>x</em>: ', dd$x,
'</br> <em>y</em>: ', dd$y,
'</br> <em>z</em>: ', dd$z)) %>%
layout(xaxis=list(title="<em>xaxis title</em>"))
### add annotation ###
pp <- pp %>%
add_annotations( x = 1,
y = 4,
text = "<em>MY ANNOTATION</em>",
xref = "x",
yref = "y",
showarrow = TRUE,
arrowhead = 7,
ax = 10,
ay = 30,
font = list(color = 'red',
family = 'sans serif',
size = 24)
)
That does not yield the expected result:

In fact, the problem lies in the fact that plotly_build generates three annotation layouts, one for each parameter of the font list:
> bpp <- plotly_build(pp)
> annotation <- bpp$x$layout$annotations
> length(annotation)
[1] 3
> sapply(annotation, function(x) x$font)
[1] "red" "sans serif" "24"
Thus, here is a way to get the expected result:
myannotation <- annotation[[1]]
myannotation$font <- list(color = 'red',
family = 'sans serif',
size = 24)
bpp$x$layout$annotations <- myannotation
bpp

> packageVersion("plotly")
[1] ‘4.5.2’
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy ví dụ heatmap R được cung cấp và kiểm tra đầu ra của plotly_build(pp), đặc biệt là x$layout$annotations. Theo dõi cách add_annotations xử lý danh sách font; hoàn tất khi color, family và size vẫn là một đối tượng font trên một annotation thay vì tạo ra ba annotation.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- r
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100