2017-05-31 185 views
0

我有下圖,我希望它格式化,使得每個座標軸上的刻度線是由粗黑邊框限定的區域的上限和下限。如何調整軸刻度線的極限與ggplot中的邊界相同?

ggplot(WPND, aes(x = Year)) + 
geom_line(aes(y=FOX_LS), colour="black", size=1.2, linetype=1) + 
geom_line(aes(y=FOX_HS), colour="red", size=1.2, linetype=1) + 
theme_light() + 
theme(axis.text.x = element_text(color= "black", size=11, angle=90, hjust = 
-2, vjust = 0.5)) + 
theme(axis.text.y = element_text(color = "black", size = 11)) + 
ylab(expression("BAI (cm "*{}^2*")")) + 
scale_x_continuous(breaks = seq(1960, 2015, by=5)) + 
scale_y_continuous(limits = c(0,60), breaks = seq(0, 60, b=10)) + 
theme(panel.border = element_rect(color = "black", fill = NA, size = 1.5), 
panel.grid.minor = element_blank(), 
panel.grid.major = element_line(color = 'grey', linetype= 'dashed'), 
axis.ticks.length = unit(-0.25, "cm"), 
axis.ticks = element_line(color = "black", size = 1), 
axis.text.x = element_text(margin = unit(c(0.5,0.5,0.5,0.5), "cm")), 
axis.text.y = element_text(margin = unit(c(0.5,0.5,0.5,0.5), "cm")))` 

圖我在ggplot取得

figure I've made in ggplot

如何我想刻度線/利潤率看

how I want the tick marks/margins to look (figure made in excel)

回答

0

你必須(在Excel中製作圖)將expand = c(0,0)自變量添加到xy比例尺:

... + 
scale_x_continuous(breaks = seq(1960, 2015, by=5), expand = c(0,0)) + 
scale_y_continuous(limits = c(0,60), breaks = seq(0, 60, b=10), expand = c(0,0)) + 
... 
+0

是的工作。謝謝! –

+0

@CameronM如果這解決了你的問題,請記得點擊這個答案旁邊的綠色檢查 – rawr