2012-12-04 55 views
3

我正在繪製使用ggplot2的散點圖。當我隱藏天平時,情節會自動因爲大一點而變大。例如:如何在使用ggplot2隱藏比例時保持圖的大小?

ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point() 

ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + 
geom_point() + 
theme(axis.title.x = element_blank(), 
     axis.title.y = element_blank(), 
     legend.position = "none") 

第二個更大。我如何避免它?我只想隱藏刻度和標籤,但保留情節作爲第一個情節,因爲我想將兩者結合起來,一個刻度和一個刻度,但保持情節大小相同。謝謝。

回答

4

棘手,但工程。 軸白色

ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point() 

+ theme (axis.title.x = element_text(family = "sans", face = "bold")) 
ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + 
    geom_point() + 
    theme(axis.title.x = element_text(family = "sans", face = "bold",colour='white'))+ 
    theme(axis.title.y = element_text(family = "sans", face = "bold",colour='white')) 

編輯:通用的解決方案

p1 <- ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + geom_point() 

p2 <- ggplot(data = iris, geom = 'blank', aes(y = Petal.Width, x = Petal.Length)) + 
    geom_point() + 
    theme(axis.title.x = element_blank(), 
     axis.title.y = element_blank(), 
     legend.position = "none") 

gA <- ggplot_gtable(ggplot_build(p1)) 
gB <- ggplot_gtable(ggplot_build(p2)) 
gA$widths <- gB$widths 
gA$heights <- gB$heights 

plot(gA) 
plot(gB) 
+0

笑非常感謝! – Autumn

相關問題