Problem:
- 无法解析传递给ggplot 2的DF变量
scale_y_continous
Aim:
- 动态执行具有比例的次轴.
我的解决办法目前是手动编写总和,这不是最好的方法,或者将DF保存在变量中并使用df$count
访问它
询问:
- 如何动态访问DF变量
.$count
?
Reproducable Example:
mtcars %>%
group_by(gear) %>%
summarise(count = n()) %>%
{
ggplot(data = . , aes(x = gear, y = count)) +
geom_col() +
coord_flip() +
scale_y_continuous(labels = comma_format(),
sec.axis = sec_axis(~./32, #sum(.$count),
labels = scales::percent,
name = "proportion")
)
}
Reference: How do I access the data frame that has been passed to ggplot()?