如何在ggplot2中设置y轴和x轴的原点/截取?
x轴的线应该精确到y=Z.
有Z=0或另一个给定的价值.
我有以下数据帧:
uniq <- structure(list(year = c(1986L, 1987L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 1986L, 1987L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 1986L, 1987L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, …Run Code Online (Sandbox Code Playgroud) 如何在ggplot2中删除x和y轴下方的绘图区域(参见下面的示例).我已经尝试了几个主题元素(panel.border,panel.margin,plot.margin)没有任何运气.
p <- ggplot(mtcars, aes(x = wt, y = mpg,xmin=0,ymin=0)) + geom_point()
Run Code Online (Sandbox Code Playgroud)

我有一个带有离散x轴的图,我想调整比例尺两侧的多余空间,使其在左侧变小,在右侧变大,因此长标签将适合。scale_x_discrete(expand=c(0, 1))在这里不是我的朋友,因为它总是同时在两侧工作。这个问题是相似的,但是解决了连续的规模问题。
我该如何实现?
set.seed(0)
L <- sapply(LETTERS, function(x) paste0(rep(x, 10), collapse=""))
x <- data.frame(label=L[1:24],
g2 = c("a", "b"),
y = rnorm(24))
x$g2 <- as.factor(x$g2)
x$xpos2 <- as.numeric(x$g2) + .25
# two groups
ggplot(x, aes(x=g2, y=y)) +
geom_boxplot(width=.4) +
geom_point(col="blue") +
geom_text(aes(x=xpos2, label=label, hjust=0))
Run Code Online (Sandbox Code Playgroud)