ggplotly with "tooltip = text" is not working in a bar graph with + and - data
Đang mở
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ả
ggplotly with "tooltip = text" does not work in a bar graph, where there is positive and negative data.
It does work if a very small number is added x_limits[1] inside geom_col.
It also works if "tooltip = text" is removed
This does not work:
library(tidyverse)
plot_data <- ggplot2::diamonds %>%
mutate(cut = stringr::str_to_sentence(cut)) %>%
group_by(cut) %>%
summarise(average_price = mean(price)) %>%
mutate(average_price = round(average_price / 1000, 1)) %>%
mutate(average_price = average_price - 4) %>%
ungroup() %>%
add_row(cut = "OK", average_price = NA) %>%
mutate(tip_text = "Hello!")
na_data <- plot_data %>%
filter(is.na(average_price))
breaks <- pretty(plot_data$average_price)
limits <- c(min(breaks), max(breaks))
plot_data <- plot_data %>%
mutate(id = row_number())
plot <- ggplot(data = plot_data) +
geom_col(aes(y = average_price, x = cut, text = tip_text)) +
coord_flip() +
scale_y_continuous(breaks = breaks, limits = limits, expand = c(0, 0)) +
geom_col(aes(y = limits[2], x = cut, text = tip_text), data = na_data) +
geom_col(aes(y = limits[1], x = cut, text = tip_text), data = na_data)
plot
plotly::ggplotly(plot, tooltip = "text")
This does works:
library(tidyverse)
plot_data <- ggplot2::diamonds %>%
mutate(cut = stringr::str_to_sentence(cut)) %>%
group_by(cut) %>%
summarise(average_price = mean(price)) %>%
mutate(average_price = round(average_price / 1000, 1)) %>%
mutate(average_price = average_price - 4) %>%
ungroup() %>%
add_row(cut = "OK", average_price = NA) %>%
mutate(tip_text = "Hello!")
na_data <- plot_data %>%
filter(is.na(average_price))
breaks <- pretty(plot_data$average_price)
limits <- c(min(breaks), max(breaks))
plot_data <- plot_data %>%
mutate(id = row_number())
plot <- ggplot(data = plot_data) +
geom_col(aes(y = average_price, x = cut, text = tip_text)) +
coord_flip() +
scale_y_continuous(breaks = breaks, limits = limits, expand = c(0, 0)) +
geom_col(aes(y = limits[2], x = cut, text = tip_text), data = na_data) +
geom_col(aes(y = limits[1] + 0.000001, x = cut, text = tip_text), data = na_data)
plot
plotly::ggplotly(plot, tooltip = "text")
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
Không có tệp mã nguồn hoặc bài kiểm thử nào được nêu. Hãy bắt đầu bằng cách chạy ví dụ R được cung cấp với plotly::ggplotly() và so sánh hành vi của tooltip khi có và không có độ lệch nhỏ của giới hạn y. Hoàn thành khi tooltip = "text" hoạt động với biểu đồ cột chứa cả dữ liệu dương và âm mà không cần workaround đó.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 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
- 42/100