1

I have two dataframes:

df1 <- data.frame(runif(100,0,0.02), 1:100)
colnames(df1) <- c("a","b")

df2 <- data.frame(runif(100,0,0.3), 1:100)
colnames(df2) <- c("a","b")

I need two scatterplots (one for each dataframe) side by side, with a log-log scale on y axis that looks exactly like this (external yticks, minor y ticks between all the labels and so) but limited to 1 (not 10):

enter image description here

I tried (scatterplot of 1 dataframe):

ggplot(df1, aes(x=factor(b), y=a)) +
  geom_point() +
  scale_y_continuous(trans = log10_trans(),
                     breaks = trans_breaks("log10", function(x) 10^x),
                     labels = trans_format("log10", math_format(10^.x))) +
  annotation_logticks()

but I still don't get what I want

1
  • 1
    What code did you try ? Commented Dec 5, 2019 at 16:30

1 Answer 1

1

adding limits=c(10^-4,1) and changing labels=comma did the work!

Final code:

ggplot(df1, aes(x=factor(b), y=a)) +
  geom_point() +
  scale_y_continuous(trans = log10_trans(),
                     breaks = comma,
                     labels = trans_format("log10", math_format(10^.x)),
                     limits=c(10^-4,1)) +
  annotation_logticks()

besides, hints how to display only significative figures (ie 1 instead of 1.0000, or 0.1 instead of 0.1000) in the comma function? thanks

Sign up to request clarification or add additional context in comments.

1 Comment

solved. for getting read of trailing 0: Instead of labels = comma use labels = function(x) format(x, scientific = FALSE, drop0trailing = T)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.