r - 如何添加美元符号以悬停?
问题描述
这是我正在使用的代码:
library(ggplot2)
library(plotly)
ggplotly(ggplot(economics_long, aes(date, value)) +
geom_line() +
facet_wrap(vars(variable), scales = "free_y", ncol = 1, strip.position = "top") +
theme(strip.background = element_blank(), strip.placement = "outside"), hoverinfo = "text", hovertext = "value: %{value:$.2f}<br>")
当您将鼠标悬停在图表上时,我试图在“值”之前包含美元符号。我现在在代码中所做的似乎不起作用。有人知道我在做什么错吗?
例如:价值:4851.20 美元
解决方案
library(ggplot2)
library(plotly)
ggplotly(
ggplot(
economics_long,
aes(
date,
value,
group = 1,
text = paste0("value: $", sprintf("%.2f", value))
)
) +
geom_line() +
facet_wrap(vars(variable), scales = "free_y", ncol = 1, strip.position = "top") +
theme(strip.background = element_blank(), strip.placement = "outside"),
tooltip = "text"
)
推荐阅读
- bash - 如何在仍然写入同一个文件的同时过滤掉特定的行?
- sql - 如何在 SQL 中旋转或旋转字符串表中的列
- internationalization - Magento 2 - 印度卢比价格分隔符之间的位数错误
- node.js - 如何使用带 node.js 的条带连接支付网关?
- javascript - Ajax 分页不适用于变量查询
- java - 带有 Viewpager 的 BottomSheet 使 arrayindex 超出范围
- javascript - CSS 规则未按预期应用
- jmeter - 获取时间戳差异以在 JMeter 中启动注销
- angular - Angular中颜色的折旧警告
- python - 我用 `pip install paramiko` 安装了 paramiko,但无法导入 paramiko