2015-05-18 56 views
4

如果我使用ggplot,那麼x軸(y == 0)的水平線與y的任何其他值相同。我想強調一下這樣一個事實,即圖的底部不是x軸,並且圖中x軸較高。我怎樣才能做到這一點?R我如何使用ggplot強調x軸?

data.df <- data.frame(Plant = c("Plant1", "Plant1", "Plant1", "Plant2", "Plant2", "Plant2"), Type = c(1, 2, 3, 1, 2, 3), Axis1 = c(0.2, -0.4, 0.8, -0.2, -0.7, 0.1), Axis2 = c(0.5, 0.3, -0.1, -0.3, -0.1, -0.8)) 

ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + geom_point(size = 5) 

回答

6

您可以突出軸與黑線

ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + 
geom_point(size = 5) + 
geom_hline(aes(yintercept = 0)) + 
geom_vline(aes(xintercept = 0)) 
3

,你也可以通過添加例如爲:

+ theme(axis.line = element_line(colour = 'red', size = 2)) 
直接改變座標軸的顏色和寬度