2016-12-28 46 views
3

我正在ggplot2中創建一個氣泡圖,需要用一個比例創建圖例。scale_size_identity()刪除大小圖例

我的工作數據如下

Var1 Var2 Var3 
A 1 10 
B 2 90 
C 3 20 
D 4 50 
E 5 70 
G 6 40 
H 7 20 

的代碼如下:

ggplot(t.df,aes(Var2,Var1,fill=Var1))+ 
    geom_point(aes(size=Var3/10),shape=21)+ 
    scale_size_identity()+ 
    theme(panel.grid.major=element_line(linetype=2,color="black",size=0.05,), 
    axis.text.x=element_text(angle=90,hjust=1,vjust=0)) 

enter image description here

當我包括scale_size_identity大小傳說自敗。任何想法如何解決這個問題?

+1

嘗試'scale_size_identity(guide =「legend」)' – baptiste

+0

我試過那個baptiste,但它不工作... – FranciscoC

+1

嗯,看起來像一個bug,你可以嘗試報告給維護者 – baptiste

回答

0

首先,如果你想兩個不同的變量傳說很容易,只要拿出scale_size_identity()和它的作品:

ggplot(t.df,aes(Var2,Var1,fill=Var1))+ 
geom_point(aes(size=Var3/10),shape=21)+ 
theme(panel.grid.major=element_line(linetype=2,color="black",size=0.05,), 
    axis.text.x=element_text(angle=90,hjust=1,vjust=0)) 

enter image description here

如果這不是你想要讓我知道,以幫助什麼

+0

謝謝D erek。但是如果我去掉scale_size_identity,那麼規模就不一樣了,點之間的差異也不是那麼明顯。例如,如果你比較這兩個圖,你會認爲最後一個粉紅色的點它的第二個圖大於第一個..有沒有辦法做到這一點,而不刪除scale_size_identity()? – FranciscoC

+2

我會盡力@FranciscoC –