r - 在R中为背靠背条形图悬停
问题描述
样品表
Animals <- read.table( header=TRUE, text='Options_ord Reason Gender Count 1 No Genuine M 24 2 Yes Genuine F -16 3 No Misclassified M 85 4 No Misclassified F 41 5 Yes Taxonomic F -2 6 Yes Taxonomic M 7 7 否 不清楚 F -41 8 是 不清楚 M 117' )
#尝试在R中制作背靠背条形图
> trace_graph3<- ggplot(Animals, aes(x = (Animals$Options_ord), y =
Animals$Count, fill = Gender)) +
geom_bar(stat = "identity") +
facet_share(~Gender, dir = "h", scales = "free", reverse_num =
TRUE) + theme_bw(base_size = 9.5)+
coord_flip() +
theme_minimal()
打印图表
打印(trace_graph3 + 实验室(y="in %", x = ""))
对于上图,我想创建一个悬停。我尝试了 ggplotly 但不幸的是它抛出了我尝试在 R 中应用非函数的错误
解决方案
我建议安装和使用 plotly 。你所需要的只是用 plotly 包装你的普通 ggplot。在交互性方面,Plotly 非常强大而简单。
install.packages('plotly')
library(plotly)
ggplotly(trace_graph3)
推荐阅读
- c++ - 我可以从第三个线程监控 boost::lockfree::spsc_queue 吗?
- css - angular-gridster2 网格大小
- c# - Azure Durable 编排功能触发两次
- r - 使用 for 循环创建包含其他列中值计数的列
- html - 如何从 div 中减去形状?
- wordpress - 如何更改基于 Woocommerce 的网站中的特定 URL?
- angular - mat-accordion 扩展面板未显示在 mat-grid-list 中
- mongodb - mongodb聚合中的项目嵌套嵌入文档
- java - 为什么 LinkedHashMap 不能排序 HashMap 而 TreeMap 可以?
- postgresql - 气流芹菜作业卡在运行状态