Stacked Barchart with total amount of bars text
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ả
Problem: I have a stacked barchart. Above each of the stacked bars I want to have a total number (i.e. the sum of the two bars - here: total). I tried to take usage of add_text but it did not work out as expected. Any suggestions what to change?
Remark: I do not want to cast the data.table object. The target frame on which the visualizations shall be made is new_frame.
Many thanks
Brief description of the problem
library(data.table)
library(plotly)
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.table(Animals, SF_Zoo, LA_Zoo)
new_frame <- data.table::melt(data, id.vars='Animals')
new_frame[, total := sum(value), by = Animals]
plot_ly(new_frame, x = ~Animals,
y = ~value,
type = 'bar',
name = ~variable,
text = ~paste(variable, value, total),
textposition = 'auto',
# insidetextfont = list(size = 10, color = 'black'),
hovertext = ~paste(
"<b>Hover text works IN/OUT</b><br>"),
hoverinfo = 'text',
hoverlabel = list(align = "left"),
showlegend = TRUE) %>%
add_text(
visible = "legendonly",
x= ~Animals,
y = ~total,
# showlegend = TRUE,
name = "Titel",
cliponaxis = FALSE,
textfont = list(size = 10)
)%>%
layout(yaxis = list(title = 'Count'), barmode = 'stack')

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 với ví dụ R có thể tái lập sử dụng data.table::melt, plot_ly và add_text, sau đó kiểm tra cách các trace của biểu đồ thanh xếp chồng định vị nhãn tổng. Hoàn thành có nghĩa là hiển thị tổng phía trên mỗi thanh xếp chồng trong new_frame mà không cast đối tượng data.table.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- plotly, 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
- 42/100