ggplot2 坐标轴刻度向内

这种问题没什么好说的,就是参数设置问题。

加载库和数据

library(ggplot2) 
data(CO2) 

ggplot(data = CO2, aes(CO2$conc, CO2$uptake, colour = Treatment)) + geom_point()

上图:

ticks_outer

图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")))

 

ticks_inner

图2 调整后的坐标轴刻度向内。

作者: 斑斑

..微笑着看着杯中的花茶一片片撑开.. ..透明的花瓣里水破开的声音很轻微..

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

7 − 3 =