plotly / plotly/plotly.R

bug with the font parameter for annotation

Đang mở
#780 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug
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:

rplot_annotation

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

rplot_annotation_good

> packageVersion("plotly")
[1] ‘4.5.2’

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.