KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to use ggplot2 to create a performance chart with a log normal y scale. Unfortunately I'm not able to produce nice ticks as for the base plot function. Here my example: library(ggplot2) library(scales) # fix RNG set.seed(seed = 1) # simulate returns y=rnorm(999, 0.02, 0.2) # M$Y are the cummulative returns (like an index) M = data.frame(X = 1:1000, Y=100) for (i in 2:1000) M[i, "Y"] = M[i-1, "Y"] * (1 + y[i-1]) ggplot(M, aes(x = X, y = Y)) + geom_line() + scale_y_continuous(trans = log_trans()) produces ugly ticks: I also tried: ggplot(M, aes(x = X, y = Y)) + geom_line() + scale_y_continuous(trans = log_trans(), breaks = pretty_breaks()) How can I get the same breaks/ticks as in the default plot function: plot(M, type = "l", log = "y") The result should look like this but not with hard-typing the breaks but dynamic. I tried functions like axisTicks() but was not successful: ggplot(M, aes(x = X,y = Y)) + geom_line() + scale_y_continuous(trans = log_trans(), breaks = c(1, 10, 100, 10000)) Thanks! edit: inserted pictures
Tags (comma-separated)
Save Edits
Cancel