I draw a graph using ggplot. Here is an example with the ggplot package:
df <- data.frame( gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30) ) ds <- plyr::ddply(df, "gp", plyr::summarise, mean = mean(y), sd = sd(y)) ggplot(df, aes(gp, y)) + geom_point() + geom_point(data = ds, aes(y = mean), colour = 'red', size = 3) + theme( axis.text.y = element_text(hjust = 3), axis.text.x = element_text(vjust = 5), axis.ticks.length = unit(-0.25, "cm"),
Here is the result:

As you can see, the ticks are inside, but the numbers for the y axis are terribly aligned, and those on the X axis overlap the ticks.
So, in the end, I need the ticks inside the graph and the axis labels (numbers) inside the ggplot graph. I heard that we should use the margin tool, but I'm not sure how to specify the fields inside the chart.
Edit: you can see how when using the margin function the numbers do not align properly ... 
source share