Search code examples
rtextggplot2geom-text

geom_text does not appear using scale_y_log10


I can add text to a ggplot using geom_text just fine (example using the cars database):

ggplot(cars, aes(speed, dist), color='blue') + 
geom_point(size=0.8) + 
geom_text(y=25, x=5, aes(label=paste("sigma == 1"), size=1.5), 
    hjust=0, parse=TRUE, color='blue')

But when I change the y scale to logarithmic, I can not get the text to appear on the graph:

ggplot(cars, aes(speed, dist), color='blue') + 
geom_point(size=0.8) + 
geom_text(y=25, x=5, aes(label=paste("sigma == 1"), size=1.5), 
    hjust=0, parse=TRUE, color='blue') + 
scale_y_log10()

I've tried varying the text size and position but can't seem to get it.


Solution

  • This works for me:

    require(ggplot2)
    g <- ggplot(cars, aes(speed, dist), color='blue')
    g <- g + geom_point(size=0.8)
    g <- g + geom_text(aes(y=25, x=5, label=paste("sigma == 1"), size=1.5), hjust=0, parse=TRUE, color='blue')
    g <- g + scale_y_log10()
    g