0

I'm trying to replicate a plot drawn by graphpad in r but I have a problem changing the y axis here is an example data and my plot codes:

library(ggplot2) data <- data.frame(names = rep(factor(LETTERS[1:3])), values = c(0.001, 0.02 ,0.95), group = rep("A",3)) ggplot(data, aes(x = group, y = values, fill = names)) + geom_bar(stat = "identity", position='stack') + scale_y_continuous(breaks = c(0.001,0.01,0.1,1), labels=c(0.001,0.01,0.1,1)) 

the result of my code is on top but I want to plot it like the image on the bottom.

enter image description here

enter image description here

1 Answer 1

1

You can convert the values to their logs, then add a constant that makes all the log values greater than 0. Then re-label the axis appropriately:

data2 <- data %>% mutate(logvalues = log10(values) - min(log10(0.0001))) ggplot(data2[order(-data2$logvalues),], aes(x = group, y = logvalues, fill = names)) + geom_col(position = 'identity') + scale_y_continuous(breaks = 0:4, labels = ~ 10^(.x-4)) 

enter image description here

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

2 Comments

Thanks for the answer, but as you can see C has the biggest value but in your plot is the smallest part. I think it's because scale_y_log10() transforms the data in the log10 scale. Is there a way to just change the y axis without transforming the data?
@RezaKhayami I see what you mean. Check out my update. Is that what you're looking for?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.