这种问题没什么好说的,就是参数设置问题。
加载库和数据
library(ggplot2) data(CO2) ggplot(data = CO2, aes(CO2$conc, CO2$uptake, colour = Treatment)) + geom_point()
上图:
图1 默认的坐标轴刻度向外。
想要让刻度的方向朝向内部,要调整一下theme中的axis.ticks.length参数,把值设为负数,但这么设置后,坐标的文字会产生偏移,因此要重新设置下axis.text.x和axis.text.y的margin参数,我试过直接设置axis.text的,但是不行。更改后的设置和图如下:
ggplot(data = CO2, aes(CO2$conc, CO2$uptake, colour = Treatment)) + geom_point() + theme(plot.margin = margin(t=10, r=20, b=20, l=20, unit = "pt"), axis.ticks.length = unit(-5, "pt"), axis.text.x = element_text(margin = margin(t=6,r=0,b=0,l=0,unit = "pt")), axis.text.y = element_text(margin = margin(t=0,r=6,b=0,l=0,unit = "pt")))
图2 调整后的坐标轴刻度向内。