ggplot X-axis is on Log10 scale, but why aren't my labels?

I have a simple plot whose x-axis goes from 1.85 to 950. I want to plot the x-axis on a log10 scale, so I use scale_x_log10()

Weirdly - the x-axis labels now just show the linear-scale values of 10, 100, and 1000 (even though the data are on a log10 scale).

How can I keep these 3 ticks, in their same position, but as a log10 value? The points should be 1, 2, and 3.

library(ggplot2)
mydf <- data.frame("dose"=c(950,475,237.5,118.75,59.37,39.6,14.8,7.4,3.7,1.85),
                   "response"=c(100,99,98.5,70,51,32,20,18,4,1))
#linear scale
ggplot(mydf, aes(x=dose, y=response)) + geom_point() + geom_line(aes(dose, response), data=mydf) 

#log10 scale is correct - but labels are not
ggplot(mydf, aes(x=dose, y=response)) + geom_point() + geom_line(aes(dose, response), data=mydf) + scale_x_log10()

People usually use log scale to extend range, but still want to see the value in the real data, not log of the data. Anyway are you looking for the following thing?

ggplot(mydf, aes(x=log10(dose), y=response)) + geom_point() + geom_line() + xlab("dose")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.