在gggplot 2中如何去除軸與面積之間的空間?我有以下數(shù)據(jù):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,當(dāng)我用: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()但是,我想刪除軸和實(shí)際圖形之間的空間。當(dāng)我加上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貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個贊
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())

MMMHUHU
TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個贊
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()

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個贊
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 關(guān)注
- 586 瀏覽
添加回答
舉報(bào)
0/150
提交
取消