简体   繁体   English

带 ggplot2 的辅助 x 轴

[英]Secondary x-axis with ggplot2

I have the following data frame:我有以下数据框:

PhiSize尺寸 CumVol累积量 Group团体
11.40 11.40 0.08 0.08 a一个
11.15 11.15 0.15 0.15 a一个
10.91 10.91 0.21 0.21 a一个
10.68 10.68 0.25 0.25 b b
10.44 10.44 0.29 0.29 b b
10.20 10.20 0.32 0.32 c c
9.95 9.95 0.38 0.38 c c

What i want to plot is a line-plot that has a secondary axis like the one above:我想要 plot 是一个线图,它有一个像上面那样的辅助轴:

具有辅助轴的所需图

So far i did到目前为止我做到了

library(ggplot2)

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

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

And got the following plot:并得到以下 plot: 在此处输入图像描述

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")

It throws:它抛出:

Error: Can't convert a double vector to function错误:无法将双向量转换为 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()))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM