2016-02-02 117 views
2

我想在x軸的頂部添加一些標籤。我怎樣才能將cm3的位移添加到這個圖的頂部,這樣我的底部有立方英寸,頂部是立方厘米?我應該用註釋去做嗎?那麼刻度線呢?我意識到這在這種情況下會產生一個醜陋的圖。 [編輯的清晰度。]ggplot頂部有一個x軸,帶有不同的標籤

# Calculate displacement in cm3 -- add this to top of plot 
# above 100, 200, 300, 400 ticks and labels for cubic inches on bottom 
cm3.lab <- seq(100,400,100) * 16.3871 
p <- ggplot(mtcars, aes(disp, mpg)) 
p + geom_point(size=5) + xlab("Cubic inches") 
p 
+0

p + geom_point(size = 5)+ xlab(「Cubic inches」)似乎讓你想要 – MLavoie

回答

2

你可以得到更好的控制在標籤&刻度線與scale_x_continuous:立方厘米和立方英寸:

p + geom_point(size=5) + scale_x_continuous(name="Displacement in cubic centimeters", breaks = c(100, 200, 300, 400), labels=c("100" = "100", "200" = "200", "300" = "300", "400" = "400")); 

更多選項

注見?scale_x_continuous並不是一回事。一定要選擇正確的!