0

In R, is there any way to have linear tickmarks on a plot with logarithmic axes? I'm plotting a bunch of log-log regressions on a scatter plot, but I want the final axes to be linear in scale. Therefore I'm starting with log data, plotting a bunch of regressions, and using "coord_trans(x="exp", y="exp")" to get the data plotted in a linear space. However, the axes still have log scales on them. Is there any way to get the axes to have linear scale as well?

Here's my code:

ggplot(oj,aes(x=logprice,y=logmove, color = factor(brand))) + geom_point() + geom_smooth(se=F, method=lm, colour="black") +
  geom_smooth(aes(dtimeslp,logmove), method=lm, se=F, colour="red", data=dft) + 
  geom_smooth(aes(mmtimeslp,logmove), method=lm, se=F, colour="green", data=mmft) + 
  geom_smooth(aes(ttimeslp,logmove), method=lm, se=F, colour="blue", data=tropft) +
  geom_smooth(aes(dtimeslp,logmove), method=lm, se=F, colour="red", data=dnft, linetype = "dashed") + 
  geom_smooth(aes(mmtimeslp,logmove), method=lm, se=F, colour="green", data=mmnft, linetype = "dashed") + 
  geom_smooth(aes(ttimeslp,logmove), method=lm, se=F, colour="blue", data=tropnft, linetype = "dashed") +
  xlab("Log(price)") + ylab("Log(sales)") + coord_trans(x="exp", y="exp")

And a picture: enter image description here

  • Can you provide some data from your dataset? Or sample data that has the same issue? That way we can play around with it and ensure our solutions work before answering your question. See: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – jesstme Mar 21 '17 at 20:36
  • 1
    If I'm remembering correctly, you should work with untransformed x and y aesthetics. Transform x and y via the appropriate `scale` function, like `scale_y_continuous(trans = "log")` (you'll likely need to set your breaks). Then you can use `coord_trans` to put plot back on original scale. – aosmith Mar 21 '17 at 20:48

0 Answers0