Tim Tim - 10 days ago 4
R Question

Add axis to ggplot facet_wrap histograms

I'm trying to create a series of histograms with the same range on the axis and crucially axis that lie at zero intercepts for both

x
and
y


mydat1 <- mydat + geom_histogram(binwidth = 5) + facet_wrap(~V2, scales = "free") + theme(axis.line.x = element_line(colour = "black", size = 0.05), axis.line.y = element_line(colour = "black", size = 0.05)) + scale_x_continuous(expand = c(0,0)) + scale_y_continuous(expand = c(0,0))


adding
+ ylim
and
xlim
to try and constrain the axis to the same ranges doesnt appear to work.

Can someone tell me where I have gone wrong?

This is what I want to produce but I need
y
to range from 0-15 and
x
from 0-400

Answer

You could use

scale_y_continuous(limits = c(0, 15))

and

scale_x_continuous(limits = c(0, 400))

Does this work?

Comments