【问题标题】:r ggvis axis format with percentage and decimal places带有百分比和小数位的 r ggvis 轴格式
【发布时间】:2017-07-18 14:57:47
【问题描述】:

我想问一下,如果有人知道关于 r 包 ggvis 中轴格式的答案。 我正在使用 % 轴格式,但我想根据 CVaR 的分布添加一些小数位。 image here 这是我的代码:

Datovka %>% ggvis(x = ~yShort,y = ~xShort,strokeWidth:=1, stroke:="blue",  strokeWidth.hover := 3) %>% layer_paths() %>% layer_paths(x = ~yNoShort, y = ~xNoShort, data = DatovkaNoShort , stroke :="green",strokeWidth:=1, strokeWidth.hover := 3)  %>%
  layer_points(~vol,~r,data = vynosyR, fill := ~isinP, key := ~id , size := 60, size.hover :=120 ) %>%
  # hide_legend("fill") %>%
  add_tooltip(all_values, "hover") %>%
  add_axis("x", title = "CVaR",format = "%" , title_offset = 50) %>%
  add_axis("y", title = "Expected return", format = "%" , title_offset = 50) %>%
  scale_numeric("y", nice = FALSE, clamp = TRUE)  %>%
  scale_numeric("x", nice = FALSE, clamp = TRUE) }

谢谢

【问题讨论】:

  • 在寻求绘图帮助时,将reproducible example 包含在示例输入数据中特别有用,这样我们就可以复制/粘贴代码来运行它并测试可能的解决方案。

标签: r decimal axis percentage ggvis


【解决方案1】:

您可以在此处阅读有关格式化的信息:https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md

df <- data.frame(x = seq(0.1, 1, 0.1) / 100, y = runif(10))
df %>% ggvis(~x, ~y) %>% layer_paths() %>% add_axis("x", format = '.2%')

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 2022-07-22
    • 2023-03-16
    • 2010-12-19
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 2015-09-30
    相关资源
    最近更新 更多