棘手但有效。白色轴
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)