带有 ggplot2 的辅助 x 轴 [英] Secondary x-axis with ggplot2

查看:77
本文介绍了带有 ggplot2 的辅助 x 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据框:

<头>
PhiSizeCumVol
11.400.08
11.150.15
10.910.21
10.680.25b
10.440.29b
10.200.32c
9.950.38c

我想要绘制的是一个线图,它有一个像上面那样的辅助轴:

What i want to plot is a line-plot that has a secondary axis like the one above:

到目前为止我做到了

library(ggplot2)

df <- data.frame(read_csv("file")

ggplot(aes(x = PhiSize, y = CumVol, color = Group ), data = df) +
  geom_line() +
  scale_x_reverse()

并得到以下情节:

但是当我添加最后一行时:

But when i add the last line:

ggplot(aes(x = PhiSize, y = CumVol, color = Group ), data = df) +
  geom_line() +
  scale_x_reverse()+
  sec_axis(2^(-df$PhiSize),name = "new")

它抛出:

错误:无法将双向量转换为函数

Error: Can't convert a double vector to function

我想得到一些帮助,拜托.

I would like to get some help, please.

推荐答案

ggplot(aes(x = PhiSize, y = CumVol, color = Group ), data = df) +
  geom_line() +
  scale_x_reverse(sec.axis = sec_axis(~ 2^(-.),
    breaks=scales::log_breaks(n = 10), labels = scales::label_number()))

这篇关于带有 ggplot2 的辅助 x 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆