0

Using this code:

ggplot(data=new.data+
geom_point(mapping=aes(x=num,y=score),shape=0)+
geom_smooth(mapping=aes(x=number,y=score),color="black",method="lm")+
xlim(2,9)+
ylim(10,25)+
xlab("Number of trials")+
ylab("Mean Outcome")+
theme(panel.grid.minor = element_blank(),
panel.background = element_blank(),axis.line = element_line(colour = "black"))

We can create the following ggplot: enter image description here

What I want to do is add a second x-axis, ideally at the top of the plot. There should be seven entries corresponding to each of the seven x-values. The issue is they are not in a one to one correspondence to the x. For example they should be 1,2,4,8,16,32,64 for example. With the 1 being above the first set of points, the 2 above the second, the 4 above the third, etc. Note that the number of trials is not an exact number hence it is not just integers but something like 2.5, etc.

Can this be done? I know that sec_axis requires a 1-1 transformation.

If it cannot be done through ggplot, is there a way to add it a different way?

Quality
  • 113
  • 6
  • 1
    Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Oct 27 '19 at 03:36
  • You may want to check this one. https://stackoverflow.com/questions/50744902/second-y-axis-in-ggplot-r – Arga Adyatama Oct 27 '19 at 09:52
  • @ArgaAdyatama that example has an axis with a one to one transformation – Quality Oct 27 '19 at 18:24

0 Answers0