gpt4 book ai didi

r - 使用 reorder_within() 后如何从字符串中删除 "___"后跟构面名称?

转载 作者:行者123 更新时间:2023-12-04 14:18:42 24 4
gpt4 key购买 nike

(我是 R 的新手)

我已使用 reorder_within() 对条形图的每个方面内的变量重新排序,但这会在字符串末尾留下“___”,后跟方面组的名称。我正在使用 ggplotly,所以它出现在悬停信息中并且看起来不雅观(而且太长)。有没有办法仍然使用 reorder_within() 来解决这个问题,或者我可以使用不同的函数在构面内重新排序吗?

我已经尝试过使用 gsub("___.*", "", column),但这会删除重新排序。

genepathways <- genepathways %>% mutate (Pathways = reorder_within (Pathways, -no_genes, Hallmark))

genepathwaysbp <- ggplot (genepathways)+
geom_col (mapping = aes (x = Pathways, y = no_genes, fill = Pathways))+
facet_wrap (~Hallmark, scales = "free")+
theme (legend.position = "none")+
theme (axis.text.x = element_blank ())+ #pathway names too long to fit, hence using plotly hover info to display this instead
scale_reordered_x()

(pp <- ggplotly (genepathwaysbp, tooltip = c("x", "y")))

使用类似的代码,在每一行和工具提示中看起来像这样:“路径名___facetgroupname”。我希望它只显示“路径名”。

(有关信息,我使用了这个:https://juliasilge.com/blog/reorder-within/)

最佳答案

如果您仔细阅读 Julia 的帖子,她会在她的 ggplot 中包含 tidytext 包中的 scale_x_reordered()。这应该删除不需要的方面组名称。

关于r - 使用 reorder_within() 后如何从字符串中删除 "___"后跟构面名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57491428/

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