I am plotting scatter plot using ggplot2. When I hide the scales, the plot automatically because a little big larger. For example:
ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point()
ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) +
geom_point() +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
legend.position = "none")
The second one is larger. How I can avoid it? I only want to hide the scales and the label but keep the plot as the first one because I want to combine the two, one with scale and one without, but keep the plot size the same. Thanks.
tricky but works. axis in white
ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point()
+ theme (axis.title.x = element_text(family = "sans", face = "bold"))
ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) +
geom_point() +
theme(axis.title.x = element_text(family = "sans", face = "bold",colour='white'))+
theme(axis.title.y = element_text(family = "sans", face = "bold",colour='white'))
p1 <- ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point()
p2 <- ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) +
geom_point() +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
legend.position = "none")
gA <- ggplot_gtable(ggplot_build(p1))
gB <- ggplot_gtable(ggplot_build(p2))
gA$widths <- gB$widths
gA$heights <- gB$heights
plot(gA)
plot(gB)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With