gpt4 book ai didi

r - ggplot2 或plotly 中带有水平条形图的表格

转载 作者:行者123 更新时间:2023-12-02 19:48:15 25 4
gpt4 key购买 nike

是否有一个 ggplot2 扩展包可以生成类似于五三八上的表格/水平条形图。理想情况下,我希望能够添加第二个甚至第三个条形图和其他文本列。

我一直在谷歌搜索并查看 ggplot 图表库,但还没有发现任何东西。

enter image description here

最佳答案

解决方法是使用DT包。这将呈现一个 HTML 表,但根据您的需要,您可以使用这个表。在RStudio中,您还可以轻松地将表格导出为任何图片格式:

library(DT)

dat <- data.frame(CANDIDATE = c("Biden", "Sanders", "Gabbard", "O'Rourke",
"Warren", "Yang", "Buttigieg", "Castro",
"Harris", "Klobuchar", "Booker", "Steyer"),
EXCLUSIVE = c(218, 100, 11, 29, 107, 14, 27, 6, 23, 8, 4, 1),
TOTAL = c(996, 683, 83, 245, 917, 187, 437, 105, 433, 180, 201, 84),
SHARE = c(21.9, 14.6, 13.1, 11.7, 11.6, 7.4, 6.2,
5.7, 5.2, 4.2, 2.2, 1.4) / 100)

datatable(dat, options = list(
columnDefs = list(list(className = "dt-left", targets = 4)))) %>%
formatPercentage("SHARE", 1) %>%
formatStyle("SHARE",
background = styleColorBar(dat$SHARE, "steelblue", -90), backgroundPosition = "left")

enter image description here

关于r - ggplot2 或plotly 中带有水平条形图的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58821644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com