2017-10-18 248 views
1

我想使圖形中只顯示氣泡顏色較大的圖形。我已經嘗試了幾個來自這個網站的建議,但到目前爲止我一直不走運。一個基本的例子如下。ggplot2 - R - 如何修復圖例中氣泡的大小

在這個例子中,我想「齒輪」的大小爲10.這可能太大,但我想驗證它是第一次工作。

library(ggplot2) 
ggplot(mtcars 
     ,aes(x=hp, y=disp, size=mpg, fill=factor(gear)))+ 
geom_point(shape=21)+ 
theme_bw()+ 
scale_size_continuous(range=c(2,15))+ 
guides(shape = guide_legend(override.aes = list(size = 10))) 

MT Cars Plot Plot Output

回答

1

guides更改shapefill將重新分的圖例的該元素的尺寸:

guides(fill = guide_legend(override.aes = list(size = 10)))