该ggthemes包实现了 tufte 的 rangeframe。您可以使用geom_rangeframewiththeme_tufte来获取范围框架。然后您可以另外添加 scalelimits 以使轴从第一个刻度开始并在最后一个刻度处结束。
require(ggthemes)
qplot(mpg, wt, data=mtcars) + geom_rangeframe() + theme_tufte()
qplot(mpg, wt, data=mtcars) +
geom_rangeframe(data=data.frame(x=c(10, 35), y=c(0, 6)), aes(x, y)) +
theme_tufte() +
scale_x_continuous(limits = c(10, 35)) +
scale_y_continuous(limits = c(0, 6))
Run Code Online (Sandbox Code Playgroud)
如果您不喜欢主题,可以查看theme_tufte获取源并相应地更改自己的主题。
qplot(mpg, wt, data=mtcars) +
geom_rangeframe(data=data.frame(x=c(10, 35), y=c(0, 6)), aes(x, y)) +
theme_bw(base_size = 16) +
theme(legend.background = element_blank(), legend.key = element_blank(),
panel.background = element_blank(), panel.border = element_blank(),
strip.background = element_blank(), plot.background = element_blank(),
axis.line = element_blank(), panel.grid = element_blank()) +
scale_x_continuous(limits = c(10, 35)) +
scale_y_continuous(limits = c(0, 6))
Run Code Online (Sandbox Code Playgroud)
或者,您也可以完全不使用轴,而是依靠网格线。
qplot(mpg, wt, data=mtcars) +
scale_x_continuous(limits = c(10, 35)) +
scale_y_continuous(limits = c(0, 6)) +
theme_bw() +
theme(panel.border=element_rect(color='white'),
axis.ticks = element_line(color='gray90'))
Run Code Online (Sandbox Code Playgroud)