r - 使用 ggplot,使用刻度中的 unit_format 和 Dollar_format 来标记文本
问题描述
我创建了以下 ggplot 来突出我的问题:
mydf = data.frame(x = c(1,2,3,4,5), y = c(1,2,3,4,5))
ggplot(data = mydf) +
geom_point(aes(x = x, y = y)) +
scale_x_continuous(labels = scales::dollar_format()) +
scale_y_continuous(labels = scales::unit_format(unit = "M"))
它给出了以下惊人的高级 ggplot 图:
我的问题很简单——我怎样才能使一个轴同时具有 $ 和 M 单位标签,以便标签显示为 $1M $2M 等。这可能吗?是否也可以减少数字和M符号之间的差距,使其显示5M
而不是5 M
一如既往的感谢!
解决方案
哈克,但有效:
ggplot(data = mydf) +
geom_point(aes(x = x, y = y)) +
scale_x_continuous(labels = scales::dollar_format()) +
scale_y_continuous(labels = scales::dollar_format(prefix="$", suffix = "M"))
推荐阅读
- javascript - 如何使用 .replace() 替换包含按位运算符的字符串部分
- bootstrap-4 - 如何将中心的授权表格与标签对齐?
- bazel - 如何升级 Bazel 感知库的 Maven 依赖项?
- react-native - 在 React Native(使用 NativeBase)中,为什么我会收到一条错误消息“期望一个字符串......”
- ios - 作为自定义 UITableViewCell 文本的一部分的 UILabel 未在 cellForRowAtIndexPath 中更新
- bots - slack 机器人可以使用 slack-api 作为管理员或完全权限用户,使用 slack 作为访客吗?
- kubernetes - minikube 以及如何调试 api 服务器错误
- javascript - 为什么当我在获取输入类型的函数中输入 {} 时我得到未定义
- javascript - 如何用透明背景为本地图标图像着色?
- reactjs - 如何为提供者使用具有多个值的 React Hooks 上下文