我正在尝试使用ggplot2和自定义X轴缩放比例scales::trans_new()。但是,当我这样做时,某些轴标签会丢失。有人可以帮我找出原因吗?
设定:
library(tidyverse)
# the data
ds <- tibble(
myx = c(1, .5, .1, .01, .001, 0),
myy = 1:6
)
# the custom transformation
forth_root_trans_rev <- scales::trans_new(
name = "sign_fourth_root_rev",
transform = function (x) { - abs(x)^(1/4) },
inverse = function (x) { x^4 }
)
Run Code Online (Sandbox Code Playgroud)
当我尝试绘制此图x = 0时,迷路的标签会丢失。
# plot - missing x-label at `0`
ggplot(ds, aes(x = myx, y = myy)) +
geom_line() +
geom_point() +
scale_x_continuous(
trans = forth_root_trans_rev, …Run Code Online (Sandbox Code Playgroud) 我希望使用自定义汇总功能汇总小标题中的每一列,该汇总函数将根据数据返回不同大小的小标题。
假设我的摘要函数是这样的:
mysummary <- function(x) {quantile(x)[1:sample(1:5, 1)] %>% as_tibble}
Run Code Online (Sandbox Code Playgroud)
可以这样将其应用于一列:
cars %>% summarise(speed.summary = list(mysummary(speed)))
Run Code Online (Sandbox Code Playgroud)
但是我想不出一种使用summarise_all(或类似方法)实现此目的的方法。
使用cars数据,所需的输出将是:
tribble(
~speed.summary, ~dist.summary,
mysummary(cars$speed), mysummary(cars$dist)
)
# A tibble: 1 x 2
speed.summary dist.summary
<list> <list>
1 <tibble [5 x 1]> <tibble [2 x 1]>
Run Code Online (Sandbox Code Playgroud)
当然,实际数据还有更多列...
有什么建议吗?