2017-02-24 24 views
0

我已經對圖例進行了繪圖。使圖例不可見但在ggplot2中保留圖形尺寸和邊距相同

enter image description here

使用圖像編輯程序,我把傳說看不見的(但在其他圖中具有相同的尺寸)

enter image description here

是否有可能做到這一點的GGPLOT2?我想在文檔中有一個2x2的圖表面板,但只有一個圖例。

+0

「我想在文檔中有一個2x2面板圖,但只有一個圖例。」通常對此的答案是刻面。你爲什麼不能使用它? – Roland

回答

2

使用這個作爲一個例子,

library(ggplot2) 

p <- ggplot(mtcars, aes(x = disp, y = hp, color = factor(cyl))) + 
    geom_point() + 
    geom_line() 

enter image description here

以下似乎工作:

p + theme(
     legend.text = element_text(color = "white"), 
     legend.title = element_text(color = "white"), 
     legend.key = element_rect(fill = "white") 
    ) + 
    scale_color_discrete(
     guide = guide_legend(override.aes = list(color = "white")) 
    ) 

enter image description here

注意,灰色繪圖區的尺寸做不變。

相關問題