在gggplot 2中如何去除轴与面积之间的空间?我有以下数据: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, 199
7L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 1986L, 198
7L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L,
2010L, 2011L, 2012L, 2013L, 2014L), uniq.loc = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("u.1", "u.2", "u.3
"), class = "factor"), uniq.n = c(1, 1, 1, 2, 5, 4, 2, 16, 16, 10, 15, 14, 8, 12, 20, 11, 17, 30, 17, 21, 22, 19, 34, 44, 56, 11, 0, 0
, 3, 3, 7, 17, 12, 21, 18, 10, 12, 9, 7, 11, 25, 14, 11, 17, 12, 24, 59, 17, 36, 50, 59, 12, 0, 0, 0, 1, 4, 6, 3, 3, 9, 3, 4, 2, 5, 2,当我用:ggplot(data = uniq) +
geom_area(aes(x = year, y = uniq.p, fill = uniq.loc), stat = "identity", position = "stack") +
scale_x_continuous(limits=c(1986,2014)) +
scale_y_continuous(limits=c(0,101)) +
theme_bw()但是,我想删除轴和实际图形之间的空间。当我加上theme(panel.grid = element_blank(), panel.margin = unit(-0.8, "lines"))我收到以下错误消息:Error in theme(panel.grid = element_blank(), panel.margin = unit(-0.8, :
could not find function "unit"对于如何解决这个问题,有什么建议吗?
3 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
expand=c(0,0)
scale_x_continuous
scale_y_continuous
panel.margin
ggplot(data = uniq) + geom_area(aes(x = year, y = uniq.p, fill = uniq.loc), stat = "identity", position = "stack") + scale_x_continuous(limits = c(1986,2014), expand = c(0, 0)) + scale_y_continuous(limits = c(0,101), expand = c(0, 0)) + theme_bw() + theme(panel.grid = element_blank(), panel.border = element_blank())
RISEBY
TA贡献1856条经验 获得超5个赞
ggplot2 version 3
expand_scale()
expand=
add=
mult=
ggplot(data = uniq) + geom_area(aes(x = year, y = uniq.p, fill = uniq.loc), stat = "identity", position = "stack") + scale_x_continuous(limits = c(1986,2014), expand = c(0, 0)) + scale_y_continuous(limits = c(0,101), expand = expand_scale(mult = c(0, .1))) + theme_bw()
FFIVE
TA贡献1797条经验 获得超6个赞
coord_cartesian
ggplot(data = uniq) + geom_area(aes(x = year, y = uniq.p, fill = uniq.loc), stat = "identity", position = "stack") + coord_cartesian(xlim = c(1986,2014), ylim = c(0,101))+ theme_bw() + theme(panel.grid=element_blank(), panel.border=element_blank())
- 3 回答
- 0 关注
- 549 浏览
添加回答
举报
0/150
提交
取消